如何插入值在谷歌表通过python只是当单元格为空/null



我试图通过python自动化google表,每次我的DF查询运行时,它都会插入当前日期的数据。

简单地说,当date列为空时,必须在程序运行时用date填充它。图片为:

示例图片

我正试图做一些类似的事情:

ws = client.open("automation").worksheet('sheet2')

ws.update (df_h.fillna("0").columns.values.tolist ())

我不能满足只是空白的空间,似乎或所有的列被替换,或所有的行,等等

通过另一个账户解决:

ws_date_pipe = client.open("automation").worksheet('sheet2')
# Range of date column (targeted one, which is the min range)
next_row_min = str(len(list(filter(None, ws_date_pipe.col_values(8))))+1)
# Range of first column (which is the max range)
next_row_max = str(len(list(filter(None, ws_date_pipe.col_values(1)))))
cell_list = ws_date_pipe.range(f"H{next_row_min}:H{next_row_max}")
cell_values = []
# Difference between max-min ranges, space that needs to be fulfilled
for x in range(0, ((int(next_row_max)+1)-int(next_row_min)), 1):
iterator = x
iterator = datetime.datetime.now().strftime("%Y-%m-%d")
iterator = str(iterator)
cell_values.append(iterator)
for i, val in enumerate(cell_values):  
cell_list[i].value = val
# If date range len "next_row_min" is lower than the first column, then fill.
if int(next_row_min) < int(next_row_max)+1:
ws_date_pipe.update_cells(cell_list)

print(f'Saved to csv file. {datetime.datetime.now().strftime("%Y-%m-%d")}')

相关内容

  • 没有找到相关文章

最新更新