python - 通过python将数据推送到谷歌电子表格的最快方法是什么

标签 python tableau-api google-sheets-api

我需要将 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/

相关文章:

python - 如何在 Python 中使用 scale_color_manual?

Javascript 相当于 Python 的 urlparse.parse_qs()?

python - Google Sheets APIv4 列分组

python - 如何使用 python 更新 MongoDB 文档?

python - 在 pandas DataFrame 中交换和分组列名

python - 用两组绘制 Pandas 数据框

tableau-api - 画面。从仪表板中的表中发布一个百分比

json - Tableau json 格式

javascript - 发送 HTTP 请求以调用 Google Sheet API 来编辑单元格

javascript - 从 Chrome 扩展程序动态创建 Google 表格?