【发布时间】:2020-08-05 20:33:00
【问题描述】:
我正在使用 df2gspread 将某个 pandas df 导入谷歌表格。该过程运行没有任何问题,但我想在 Gsheets 中操作的数字信息作为文本导入。当我对存储为文本的数据使用基本数学运算时,它可以工作,但是当我尝试使用表格函数(例如 sum、average 和其他任何东西)时,返回的值始终为零。另外,如果我尝试在 gsheet 本身中手动将文本转换为数字,它没有任何效果。
代码如下:
import pandas as pd
import gspread as gs
from df2gspread import df2gspread as d2g
result = tera.execute_response("select * from table_drive")
df = pd.DataFrame(result)
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'json_gsheets.json', scope)
gc = gs.authorize(credentials)
spreadsheet_key = 'insert_wks_key_here'
wks = 'import'
d2g.upload(df, spreadsheet_key, wks, credentials=credentials, row_names=False,start_cell = 'B3')
这会正确插入数据,但其中的所有内容都不可撤销地以文本形式存在。
谁能帮忙?
提前致谢!
【问题讨论】:
标签: python pandas google-sheets google-sheets-api gspread