我观看了以下视频,其中演示了有关未经身份验证访问Google表格的演示:-
https://youtu.be/t6WSY9D_ORQ?list=LL
根据视频,我无法使用以下代码访问熊猫的Google表格:-
import pandas as pd
sheet_id = "my_sheet_id"
r = "https://docs.google.com/spreadsheets/d/{}/export?format=csv".format(sheet_id)
df = pd.read_csv(r)
df.head()
我得到的例外是:-
HTTP Error 400: Bad Request
此代码适用于以下公开的Google表格:-
https://docs.google.com/spreadsheets/d/1x9p3nqTf9fBx8I4lb3WMC_K0BLaIU8Z-7kj7MVani3U/edit?usp=sharing
sheet_id = "1x9p3nqTf9fBx8I4lb3WMC_K0BLaIU8Z-7kj7MVani3U"
我是否需要添加一些标题/参数才能使其正常工作?
答案 0 :(得分:1)
如何如下修改端点?可以在Drive API中“文件:获取”方法的exportLinks
处看到此端点。 Ref
r = "https://docs.google.com/spreadsheets/d/{}/export?format=csv".format(sheet_id)
r = "https://docs.google.com/spreadsheets/export?id={}&exportFormat=csv".format(sheet_id)