根据数据帧时间戳索引仅将增量数据上传到Google Sheet API

时间:2019-06-11 07:07:55

标签: python google-api google-sheets-api

我尝试仅添加运行我的python脚本填充Google工作表时所做的最后刷新以外的行。当我df_to_sheet上传最近90天并删除Google工作表的内容时。但我只想在Google工作表中最后填充的行之后添加最后几天。

代码:

url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/ohlcv/historical'
parameters = {
   'symbol':'BTC',
  #'time_start':'2019-04-01',
  #'time_end':'2018-09-02',
   'count':'90',
   'interval':'daily',
   'convert':'JPY'
}
headers = {
  'Accepts': 'application/json',
  'X-CMC_PRO_API_KEY': 'XXXXXXXXXX',
}
session = Session()
session.headers.update(headers)
response = session.get(url, params=parameters)
data = json.loads(response.text)
used_list = [
item['quote']['JPY']
for item in  data['data']['quotes']
]
BTCJPY = pd.DataFrame.from_records(used_list)
BTCJPY['timestamp'] = pd.to_datetime(BTCJPY['timestamp'])
BTCJPY['Volatility'] = 
BTCJPY['close'].pct_change().dropna().rolling(2).std().dropna()
BTCJPY = BTCJPY.set_index('timestamp')

spread = Spread(creds, 'Market_data')
spread.df_to_sheet(df= BTCJPY, sheet= 'BTCJPY', replace= False, 
freeze_headers= True)

示例:

 timestamp               close      high        low          market_cap      open      volume   
 2019-03-14 23:59:05    438531.5003 441005.0109 435953.2758 7713215224614   436431.5612 1171183503859   
 2019-03-15 23:59:06    441346.8227 442197.187  436121.4276 7763577487205   437530.7244 1046755356646

0 个答案:

没有答案