简体   繁体   English

在 gspread_pandas 中使用 df_to_sheet 时锁定列以防止删除

[英]Locking columns from deleting when using df_to_sheet in gspread_pandas

I am using a gspread_pandas + internal library that helps me get data from sfdc and paste it into a G-Sheet that has columns AN for data and OQ has formulas working off on the data.我正在使用 gspread_pandas + 内部库,它可以帮助我从 sfdc 获取数据并将其粘贴到 G-Sheet 中,该 G-Sheet 具有用于数据的 AN 列,并且 OQ 具有对数据起作用的公式。 This data needs to be updated daily and NOT appended in the sense that the code needs to clear info from Col AN and replace it with the latest data.此数据需要每天更新,而不是附加在代码需要从 Col AN 清除信息并将其替换为最新数据的意义上。

The issue is that when the code runs it is removing EVERYTHING on my G-Sheet including OQ which has formulas.问题是,当代码运行时,它会删除我的 G-Sheet 上的所有内容,包括具有公式的 OQ。

I am at a loss here because it is not feasible for me to keep the data and working sheets separately as this adds a lot of space pressure to the G-Sheet to have one sheet with data and another sheet with data+formulas.我在这里不知所措,因为将数据和工作表分开保存对我来说是不可行的,因为这给 G-Sheet 增加了很大的空间压力,让一张带有数据的表格和另一张带有数据+公式的表格。

Here is my code:这是我的代码:

import pandas as pd
from gspread_pandas import Spread

import sys
sys.path.append("/files/apac")

import datascience_APAC as ds

data = ds.sfdcApi_to_pd("00O3a000004xr80")

wkbk = Spread("****@gmail.com", "1F1XUTuRTV6nLcTImDAuDTTWFpSVfUAKY7t3oElkhWBo")

wkbk.clear_sheet(sheet="Test")
time.sleep(5)
wkbk.df_to_sheet(data, index=False, replace=True, sheet="Test")

The issue here is that df_to_sheet has parameters that coerce it to start from a particular column and row but does not have a parameter for the number of columns to determine what to clear and therefore clears everything including my formulas.这里的问题是 df_to_sheet 具有强制它从特定列和行开始的参数,但没有用于确定要清除的列数的参数,因此会清除包括我的公式在内的所有内容。

Please help this newbie.请帮助这个新手。 :) :)

I use.values_clear() from gspread library:我使用gspread库中的.values_clear() :

#use your own credentials to login
from google.colab import auth
auth.authenticate_user()

import gspread
from oauth2client.client import GoogleCredentials

gc = gspread.authorize(GoogleCredentials.get_application_default())

sh = gc.open_by_key("1F1XUTuRTV6nLcTImDAuDTTWFpSVfUAKY7t3oElkhWBo") #your file key 

sh.values_clear("Test!A:J") #example range, use your own as per need

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM