I am trying to create a loop which will return for each ticker, 1. a different data frame (by the name of ticker) 2. with a conversion of the time column to "normal" day 3. and it (the new time) will be used as index for that data frame.
If I run it for each ticker it's working without problem. I appreciate your help!
import requests
import pandas as pd
desired_width = 320
pd.set_option('display.width', desired_width)
data = pd.DataFrame()
tickers = ['BTC', 'ETH', 'XRP'] # pools of tickers to get
for t in tickers: # a loop to get data ticker by ticker
url = 'https://min-api.cryptocompare.com/data/histoday' + \
'?fsym=' + \
t +\
'&tsym=USD' + \
'&limit=600000000000' + \
'&aggregate=1' + \
'&e=CCCAGG'
response = requests.get(url)
data[t] = response.json()['Data']
#the following 2 lines I failed to execute
#data[t]['time'] = pd.to_datetime(data[t]['time'], unit='s')
#data[t].index = data[t]['time']
print("downloading data for: " + t)
print("data for:" + t, data.head(5))
My results is one data frame for all three tickers:
data for:XRP BTC
ETH XRP 0 {'time': 1342742400, 'close': 8.52, 'high': 8.... {'time': 1342742400, 'close': 0, 'high': 0, 'l... {'time': 1342742400, 'close': 0, 'high': 0, 'l... 1 {'time': 1342828800, 'close': 8.85, 'high': 9.... {'time': 1342828800, 'close': 0, 'high': 0, 'l... {'time': 1342828800, 'close': 0, 'high': 0, 'l... 2 {'time': 1342915200, 'close': 8.41, 'high': 8.... {'time': 1342915200, 'close': 0, 'high': 0, 'l... {'time': 1342915200, 'close': 0, 'high': 0, 'l... 3 {'time': 1343001600, 'close': 8.45, 'high': 9.... {'time': 1343001600, 'close': 0, 'high': 0, 'l... {'time': 1343001600, 'close': 0, 'high': 0, 'l... 4 {'time': 1343088000, 'close': 8.6, 'high': 8.8... {'time': 1343088000, 'close': 0, 'high': 0, 'l... {'time': 1343088000, 'close': 0, 'high': 0, 'l...
I am using python 3.6 with pycharm + anconda on Windows 10