【发布时间】:2019-10-22 00:01:28
【问题描述】:
我目前有一个包含这种格式信息的 pandas DataFrame:
date new builds new houses new homes help to buy
0 2014-06-08 5 29 79 11
1 2014-06-15 5 30 79 11
2 2014-06-22 6 31 82 12
3 2014-06-29 5 31 82 12
4 2014-07-06 5 33 86 12
5 2014-07-13 5 33 88 13
6 2014-07-20 5 33 87 12
7 2014-07-27 5 33 86 13
8 2014-08-03 5 32 86 13
9 2014-08-10 6 31 83 12
10 2014-08-17 5 30 86 11
我正在尝试通过 gspread 包并使用 sheet.update_cell 函数将这些信息解析到 Google 表格中,但我不断收到错误
int32 类型的对象不是 JSON 可序列化的
我能找到的该数据类型的唯一引用是 Dataframe 中的值。
我尝试过df['new builds'].astype(int),但这只是将该列中的数据保留为int32 类型,我也尝试先将其转换为字符串,然后使用df['new builds'].astype(str).astype(int) 键入int,但没有运气。
仅供参考,这是我尝试使用的代码,用于将 DataFrame 中的所有数据推送到工作表中
number_of_columns = len(data.columns)
number_of_rows = data.shape[0]
for i in range(0, len(keyword_list)):
column_loop = i + 1
type(column_loop)
for x in range(number_of_rows):
row_loop = x + 1
type(row_loop)
sheet.update_cell(column_loop, row_loop, data.loc[x,keyword_list[i]])
【问题讨论】:
标签: python json pandas numpy dataframe