reading csv file into python pandas

Question:

I want to read a csv file into a pandas dataframe, but I get the following error

error

when executing this code:

filepath = "https://drive.google.com/file/d/1bUTjF-iM4WW7g_Iii62Zx56XNTkF2-I1/view"
df = pd.read_csv(filepath)
df.head(5)
Asked By: Nazar

||

Answers:

Try the following code snippet to read the CSV from Google Drive into the pandas DataFrame:

import pandas as pd

url = "https://drive.google.com/uc?id=1bUTjF-iM4WW7g_Iii62Zx56XNTkF2-I1"
df = pd.read_csv(url)
df.head(5)
Answered By: Ezra Katz

To retrieve information or data from google drive, at first, you need to identify the file id.

import pandas as pd

url='https://drive.google.com/file/d/0B6GhBwm5vaB2ekdlZW5WZnppb28/view?usp=sharing'
file_id=url.split('/')[-2]
dwn_url='https://drive.google.com/uc?id=' + file_id
df = pd.read_csv(dwn_url)
print(df.head())
Answered By: Sachin Liyanage
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.