Google Colab is a powerful tool that allows you to run Python code in the cloud. This can be useful for a variety of tasks, including data analysis and machine learning. One of the lesser known features of Google Colab is that you can also import or upload files stored on your local drive. In this article, we will show you how to read a file from your local drive in Google Colab using a quick code sample.
There are a few reasons why you as a data scientist might need to learn how to read files from your local drive in Google Colab.
Executing the code below will prompt to select a file from the local drive and upload.
import pandas as pd
import io
from google.colab import files
uploaded = files.upload()
Once done with the above, all you need to do is execute the following code. The “FileName.csv” should be the name of the file that you uploaded.
df = pd.read_csv(io.BytesIO(uploaded['FileName.csv']))
In order to test if the file is loaded appropriately, execute the following command:
df.head()
If you have any questions about how to use Google Colab or need help getting started, don’t hesitate to reach out. We’re here to help!
Large language models (LLMs) have fundamentally transformed our digital landscape, powering everything from chatbots and…
As Large Language Models (LLMs) evolve into autonomous agents, understanding agentic workflow design patterns has…
In today's data-driven business landscape, organizations are constantly seeking ways to harness the power of…
In this blog, you would get to know the essential mathematical topics you need to…
This blog represents a list of questions you can ask when thinking like a product…
AI agents are autonomous systems combining three core components: a reasoning engine (powered by LLM),…
View Comments
Hello, thanks for your post, is there a way to upload files directly to a specific folder? after using 'uploaded = files.upload()', the files are in the root folder, as I want to upload many files I would like t have them for example in a folder 'Uploaded', is that possible?