将csv文件读入python pandas

pgpifvop  于 2023-04-10  发布在  Python
关注(0)|答案(2)|浏览(147)

我想将一个csv文件读入pandas Dataframe ,但得到以下错误

执行此代码时:

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

ovfsdjhp1#

要从Google Drive中检索信息或数据,首先,您需要识别文件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())
bvjxkvbb

bvjxkvbb2#

尝试以下代码片段将CSV从Google Drive读取到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)

相关问题