python - 使用 python 将数据框上传到 google 表格时出错?

标签 python pandas google-sheets google-sheets-api pygsheets

我正在获取谷歌工作表作为 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/

相关文章:

python - Seaborn 中的 FacetGrid 数据标签

javascript - 将工作表复制到新电子表格,将单元格值添加到新电子表格名称的末尾

python - 将 Pandas 时间戳转换为时间(寻找比 .apply 更快的东西)

python字典是线程安全的吗?

Python错误: Boolean Series key will be reindexed to match DataFrame index

python - 计算 pandas 中不连续的行索引集的列值差异

c# - 垃圾收集和作用域在 C# 中是如何工作的?

python - “密集”对象没有属性 'op'

validation - Google 表格中数字的数据验证不起作用

google-sheets - 如何对前 5 个有值的单元格求平均值