我从一个网站上下载了一份货币清单。所有的价格都从2018-01-01开始,除了一种货币,从2015年开始。我怎么能从2018年开始有这个系列,这样我就可以从2018年开始把它们组合起来
我试过loc and datetime
,但什么都没用。代码如下
base_polo_url = 'https://poloniex.com/public?command=returnChartData¤cyPair={}&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
任何帮助都将不胜感激
如果你只想在2018年之前过滤数据,你可以简单地做
编辑:为此,您需要一个日期时间索引:
相关问题 更多 >
编程相关推荐