Python Data Analysis with Google Colab & Gemini AI: A Beginner's Tutorial

Updated on Oct 30,2025

Table of Contents

Data analysis is increasingly vital across various fields. This tutorial demonstrates how to leverage Python, Google Colab, and Gemini AI to conduct data analysis, even without extensive programming knowledge. Google Colab provides a ready-to-use environment, and Gemini AI assists with code generation, making the process accessible to beginners.

Key Points

Utilize Google Colab for a hassle-free Python environment.

Employ Gemini AI for code generation assistance.

Learn to import data from CSV files.

Master data analysis basics with Pandas.

Create data visualizations with Matplotlib.

Explore practical data analysis examples.

Getting Started with Python Data Analysis

Why Python, Google Colab, and Gemini AI?

This Tutorial explores Python, Google Colab, and Gemini AI, which offer several advantages for data analysis. Python's extensive libraries, especially Pandas, are invaluable for data manipulation and analysis. Google Colab provides a cloud-based environment, removing the need for local installations. Google Colab is a virtual server with Python and all necessary libraries pre-installed

. Gemini AI's code generation features further simplify the process, making it less daunting for beginners.

This combination offers a streamlined and accessible pathway into data analysis, allowing users to focus on insights rather than wrestling with complex coding setups.

Keywords: Python, Data Analysis, Google Colab, Gemini AI, Pandas

Accessing Google Colab and Setting Up

To begin, navigate to colab.research.google.com in your web browser

. This opens Google Colab, a free, cloud-based platform. Create a new notebook within Google Colab by clicking 'File' then 'New Notebook.' This creates a blank Python environment where you can start coding. You can find the 'File' option on the top left corner of the screen. No local installations are needed, making it immediately accessible.

This user-friendly environment promotes quick and efficient data exploration.

Keywords: Google Colab, Python environment, data exploration

Data Acquisition: Importing a CSV File

To analyze data, first, some data is required. While data can be sourced from Excel files, Google Sheets, or SQL databases, this tutorial uses a simple CSV file for demonstration purposes. CSV, or Comma Separated Values, is a common format for storing tabular data. A CSV file from the Chicago Data Portal is downloaded.

To acquire a dataset, navigate to data.cityofchicago.org , a public data portal. This Chicago Data Portal contains various datasets.

Keywords: data source, csv file, chicago data portal

Locating and Downloading the Traffic Crashes Dataset

From the Chicago Data Portal homepage, you can browse the data catalog or search for specific datasets

. For this tutorial, the 'Traffic Crashes - Crashes' dataset is selected from the 'Transportation' category. After landing on the description page, you can find a dataset with 925K rows and 48 columns.

This dataset provides information about each traffic crash on city streets within the City of Chicago limits and under the jurisdiction of the Chicago Police Department (CPD). To download the dataset, click on 'Export' in the top right corner and choose 'CSV' as the format. Once the download is initiated, wait for the file to download onto your computer .

Keywords: traffic crashes, transportation data, dataset download

Importing Pandas Library in Python

To begin coding on Google Colab. Now switch back to the Google Colab notebook and start adding code. Every python data analysis needs a code called Pandas library. Import the Pandas library by entering the code:

import pandas as pd

The common approach is to rename it to ‘pd,’ making it easier to reference. Click the Play button to run the code and initiate the code block.

Keywords: pandas library, import pandas, data analysis python

Upload the CSV Data to Google Colab

To work with the downloaded CSV data, it needs to be uploaded into the Google Colab environment

. On the left-hand side of the Google Colab interface, find the Files icon. This section shows the files currently available in the Colab environment. Click the 'Upload' button and choose the downloaded CSV file from your computer.

Bear in mind that these files are for temporary and will be gone after runtime terminates. Once upload is complete, rename the file in Colab file section with a shorter name.

Keywords: Google Colab file upload, uploading csv data, data access

Reading the CSV File into a Pandas Dataframe

Now that the Pandas library has been imported and data uploaded, the next step is to read the data. To load this data to Pandas library, run this code:

df = pd.read_csv('Traffic_Crashes.csv')

pd.read_csv(‘filename’) allows Pandas to easily read data from the CSV file and create what’s called a “Data Frame.” A Data Frame will display the data in an organized table, making it more readable and convenient to use.

In programming, indexes start with ‘0’ rather than ‘1.’ In Google Colab, simply enter df then hit the run button to display your Data Frame.

Keywords: pandas dataframe, csv read, data frame display

Getting Help from Gemini AI

To use Gemini AI to assist data analysis, find the Gemini Icon on the upper right corner of the Google Colab page. Use this box as you would other AI chatbots, such as Google Bard, or ChatGPT, and the chatbot will generate code to help write lines. Be sure to review and verify any code provided by Google Gemini AI.

Keywords: google gemini, data analysis tool, AI code generation

Removing Unnecessary Data Using Drop Columns

To make data analysis easier, you may want to exclude columns . Google Gemini AI can assist if you ask the proper question to the program:

Delete columns Crash Record ID, Crash Date from the Pandas Data Frame df.

To ensure correct function:

  • Ensure quotations are the correct style (“” vs. ‘’).
  • Ensure the quotation encloses Crash Record ID and Crash Date.

Now, let’s use code with caution. The correct code generated should look like:

df = df.drop(['CRASH_RECORD_ID', 'CRASH_DATE_EST_I'], axis=1)

Running the lines now will not print, but you have deleted those columns of data in the notebook.

Keywords: drop columns, reduce data, pandas analysis

Inspecting an Individual Row of Data

To inspect the Data Set, every data point can be displayed, but due to the wide range of Data Points, an inspection on a single row is best [t: 133]. Run this code to inspect a row:

df.iloc[0]

Remember that we want to avoid ‘Print’ statements. This code then will provide a display of the selected row. Inspecting the Data Frame is helpful in deciding what to include, and exclude.

Keywords: data set columns, individual rows, inspect dataset

Data Summarization: Total Crashes by Year

Data collection can be summarized by category using the Group By coding Prompt [t: 0].
get the number of crashes by year

When prompted, Google Gemini AI will generate this code for Python:

df['CRASH_YEAR'] = df['CRASH_DATE'].dt.year
crashes_by_year = df.groupby('CRASH_YEAR').size()
print(crashes_by_year)

If you prefer not to use the ‘Print()’ display, copy “crash_by_year” or the display variable name to the next code box.

Now there should be an output of record data broken down by ‘Year’.

Keywords: Group by statement, Google Gemini AI, traffic crashes analysis

Data Visualizations: Creating a Bar Chart

To create visualization from Python language:

Create a Chart from crashes_by_year

To do so, you will receive generated Python, however, Google Gemini AI needs another import. Google Gemini AI needs help understanding the new code.

import matplotlib.pyplot as plt
crashes_by_year.plot(kind='bar', figsize=(10, 6))
plt.title('Number of Crashes by Year')
plt.xlabel('Year')
plt.ylabel('Number of Crashes')
plt.show()

Now, here’s how the prompt should be setup:

change the color of the bars to green

When ready, copy the new code into the second code box and display new code. Be sure to separate import and the graphing into separate boxes.

Keywords: chart creation, create chart code, pandas dataframe

Calculate Total Sum in Pandas Dataframe

Get total sum from the crashes from the crashes_by_year 

Google Gemini AI will generate the following code to help:

total_crashes = crashes_by_year.sum()
print(total_crashes)

Now you have all of the crashes calculated in total number. With the new dataset, total crash number can be displayed.

Keywords: pandas sum function, sum code

Breakdown by Weather Condition in Pandas Dataframe

total number of records by year broken down by WEATHER_CONDITION

Google Gemini AI will generate the following code to help:

report = crashes_by_year.pivot(index='CRASH_YEAR', columns='WEATHER_CONDITION', values='COUNT')
print(report)

You can select these results by clicking an icon near the matrix of information and display a user friendly version, sortable by column.

Keywords: Google Gemini, Pivot Table, Data Report

Tips For Success

Tips For Success

Here are a few additional tips to improve your Python and data analyses

  • Ensure to properly sanitize datasets before beginning.
  • Make sure to understand the basics of code to improve your understanding and prompt skills.
  • Learn to use your resources to display your information for analysis to improve code creation.

FAQ

Is Google Colab really free?
Yes, Google Colab with Python, pandas and Gemini offers Data Analysis at a no cost option.
What if I need to generate this for the long term?
Google Gemini with Python generates temporary files, be sure to store them. You can always upload the new notebook file and it will automatically generate the code for you, as long as you have saved your previous code.

Related Questions

What Are other AI options?
Many open and closed source alternatives are available. The best approach is to use the tool to learn on your own. That will enable users to learn how to manage and adjust code accordingly. Be sure to use AI cautiously with legal advice due to ethical practices being uncertain with AI and potential privacy issues

Most people like