Python 3 - 系列开始 d

2024-06-10 13:19:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我从一个网站上下载了一份货币清单。所有的价格都从2018-01-01开始,除了一种货币,从2015年开始。我怎么能从2018年开始有这个系列,这样我就可以从2018年开始把它们组合起来

我试过loc and datetime,但什么都没用。代码如下

base_polo_url = 'https://poloniex.com/public?command=returnChartData&currencyPair={}&start={}&end={}&period={}'
start_date = datetime.strptime('2018-01-01', '%Y-%m-%d') # get data from the start of 2018
end_date = datetime.now() # up until today
period = 300 # pull daily data (300 seconds per day)

def get_crypto_data(poloniex_pair):
    '''Retrieve cryptocurrency data from poloniex'''
    json_url = base_polo_url.format(poloniex_pair, start_date.timestamp(), end_date.timestamp(), period)
    data_df = get_json_data(json_url, poloniex_pair)
    data_df = data_df.set_index('date')
    return data_df

altcoins = ['ETH','LTC','XRP','STR','DASH','SC','XMR','XEM','MAID']

altcoin_data = {}
for altcoin in altcoins:
    coinpair = 'BTC_{}'.format(altcoin)
    crypto_price_df = get_crypto_data(coinpair)
    altcoin_data[altcoin] = crypto_price_df

任何帮助都将不胜感激


Tags: jsonurldfdatagetdatetimedate货币