How to analyze your local dataset with Google Golab?

DamenC
3 min readJun 15, 2023
Photo by Shahadat Rahman on Unsplash

Google Colaboratory, or “Colab” for short, is a product from Google Research. Colab allows you to write and execute arbitrary python code through the browser, and is especially well suited to machine learning, data analysis and education. One the about using Colab that bothers me is that sometimes it is difficult to use when analyzing data file stored in your local environment. In this post, I will show you a convenient way to prepare your local dataset ready for analysis on Colab. There are 5 steps in total.

Step 1: Upload your dataset to Google Drive

Image by Author

In "Folders", create a folder for example named "data". Then upload your local data file to that folder.

In this example, I uploaded a CSV file called "movie_data.csv" to a folder called "data".

Image by Author

Step 2: Create a notebook in Colab

Just create a Python notebook in the way you do in Jupyter notebook.

Image by Author

Step 3: Allowing notebook to access Google Drive files

Then click the folder icon marked by the orange circle shown in the image above. You will see the following:

Image by Author

Then click the folder icon with the Google Drive mark on it, like the image above.

After clicking, you will see the following window below. Please choose "Connect to Google Drive".

Image by Author

Step 4: Copy the path to notebook

The next step is important. We need to copy the path of the data file to the notebook. First, let’s find that file.

Image by Author

Once you allow the notebook to access to you Google Drive. You will see "drive" icon appear on the left. It may take a few seconds depending on your internet connection. Then find the "data" folder that we just created. Right "click movie_data.csv" and click "Copy path".

Step 5: Read data

This is the final step. In the notebook, we first create a "path" variable to paste the path that we copied. Then all we need to do it to read that path like the following:

Image by Author

Summary

As I checked some posts about this topic, many of them try to provide several methods and sometimes omit several key steps. The purpose of this post is to provide you a clearly defined framework to work with your local file using Colab. I capture the image of every step and I hope you find this procedure easy to follow.

--

--

DamenC

MS in Informatics; MA in Area Studies. Interested in using AI for sustainable development of nature and human societies. Contact me at: s2226089@u.tsukuba.ac.jp