DEV Community

Duvan Moreno Cardona
Duvan Moreno Cardona

Posted on

9 3

How load CSV files in your Drive with Pandas.

1. Import Drive

First we need import Drive in our Note Book, use this commands:

from google.colab import drive
Enter fullscreen mode Exit fullscreen mode

2. Mount your Google Drive

Mount your Google Drive at the specified mount-point path.

drive.mount('/content/drive')
Enter fullscreen mode Exit fullscreen mode

This command ask for permissions for use your Drive

3. Import Pandas

For load CSV in our Notebook, we use:

Import Pandas

import pandas as pd
Enter fullscreen mode Exit fullscreen mode

4. Load CSV in Drive with Pandas

Read CSV file with Pandas

pd.read_csv('/content/drive/My Drive/{csv location}')
Enter fullscreen mode Exit fullscreen mode

example

pd.read_csv('/content/drive/My Drive/Colab Notebooks')
Enter fullscreen mode Exit fullscreen mode

If you CSV file has many pages, you can use this line

pd.read_excel('{csv_location}', sheetname='{sheetname}')
Enter fullscreen mode Exit fullscreen mode

example

pd.read_excel('/content/drive/My Drive/Colab Notebooks', sheetname='january accounting')
Enter fullscreen mode Exit fullscreen mode

If the columns in your CSV is separate with special character, you can use:

pd.read_csv('/content/drive/My Drive/{csv location}' , sep='{special_character}')
Enter fullscreen mode Exit fullscreen mode

example

pd.read_csv('/content/drive/My Drive/Colab Notebooks' , sep='|')
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay