【问题标题】:reading csv file into python pandas将csv文件读入python pandas
【发布时间】:2021-08-19 19:22:37
【问题描述】:
我想将 csv 文件读入 pandas 数据帧,但在执行以下代码时我得到了一个 error:
filepath = "https://drive.google.com/file/d/1bUTjF-iM4WW7g_Iii62Zx56XNTkF2-I1/view"
df = pd.read_csv(filepath)
df.head(5)
【问题讨论】:
标签:
dataframe
export-to-csv
【解决方案1】:
要从 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())
【解决方案2】:
尝试使用以下代码 sn-p 将 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)