我正在获取谷歌工作表作为 pandas 数据框,然后在 df 中添加一列,然后将其上传回来。我遇到这个错误:
Object of type 'int64' is not JSON serializable
下面是代码:
#reading and writing on google sheets
gc = pygsheets.authorize(service_file="/Projects/big_query_funnel_v1/input/AppFunnelgs-e1968da.json")
sheet=gc.open('Daily Drop Offs Summary')
wks = sheet.worksheet_by_title('New_Funnel')
#converting to pandas df
ds = wks.get_as_df()
#making a new column
ds.insert(loc=1, column=str(dates), value=edf.vals)
print(ds.head())
wks.set_dataframe(ds, 'A1')
我在最后一行代码中遇到错误,即在上传回 df 时。
最佳答案
Json 不理解 numpy 整数,因此在上传回 Google 表格之前,需要将数据帧转换为字符串或整数。
ds = ds.applymap(str)
关于python - 使用 python 将数据框上传到 google 表格时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55932703/