我需要将 1.18 MB 或大约 10,000 行数据从服务器上的 csv 文件推送到 Google 表格以供 Tableau 读取。
数据从 Google DFP 进入 csv 文档。我之前一直使用 gspread 库用 csv 数据更新 google 工作表,但是对于 10,000 条记录以及每条记录发布约 30 秒的情况,这种方法将无效。
是否有比使用 gspread 库更快的方法将 csv/txt 文件的内容复制到 Google 电子表格?最好使用 Python。
更新: 我正在尝试这种批量更新单元格的方法。
raw_dfp = pd.read_csv('live_dfp_UTF.csv', error_bad_lines=False)
sample5 = raw_dfp.iloc[:3, :]
rows, col = sample5.shape
doc.resize(1, 7)
doc.clear()
doc.resize(rows + 1, col)
column_names = ['', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K']
cell_range = 'A1:' + column_names[col] + str(rows)
cells = doc.range(cell_range)
# To use this next line??
# flattened_data = np.flatten(sample5)
for x in range(rows):
cells[x].value = sample5[x].decode('utf-8')
doc.update_cells(cells)
最佳答案
为什么不将 csv 文件中的所有数据加载到 pandas 数据框中,然后将其作为一个整体推送到 Google 电子表格中?
这个库可能会有帮助:https://github.com/maybelinot/df2gspread
关于python - 通过python将数据推送到谷歌电子表格的最快方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42651604/