DEV Community

Duvan Moreno Cardona
Duvan Moreno Cardona

Posted on

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

Top comments (0)