用变量调用字典键和值

时间:2019-05-28 01:13:24

标签: python dictionary

功能:

print

数据来源:

def daily_volume_historical(symbol, comparison_symbol, all_data=False, limit=1, aggregate=1, exchange=''):
url = 'https://min-api.cryptocompare.com/data/histoday?fsym={}&tsym={}&limit={}&aggregate={}'\
        .format(symbol.upper(), comparison_symbol.upper(), limit, aggregate)
if exchange:
    url += '&e={}'.format(exchange)
if all_data:
    url += '&allData=true'
page = requests.get(url)
data = page.json()['Data']
df = pd.DataFrame(data)
df.drop(df.index[-1], inplace=True)
#pd.to_numeric(df.time)
#df.apply(pd.to_numeric, errors='ignore')
df['timestamp'] = [datetime.fromtimestamp(d) for d in df.time]
df.set_index('timestamp')
return df

代码:

1            asks:
2           261.45
10    914831.84339
7                5
Name: 552, dtype: object

在函数中,我想从数据源中选择“ 5”作为字典[data [7]]的键。然后,“ BTC”为值[0],“ JPY”为值[1]。任何帮助将不胜感激。

错误:

curr = {'1':['BTC','USD'],   '3':['BTC','EUR'],  '5':['BTC','JPY'],...
volu = daily_volume_historical(curr[data[7]][0], curr[data[7]][1], exchange= 'Liquid').volumeto

编辑:已解决。答案是:

 volu = daily_volume_historical(curr[data[7]][0], curr[data[7]][1], exchange= 'Liquid').volumeto
   File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pandas/core/generic.py", line 1492, in __hash__
' hashed'.format(self.__class__.__name__))
 TypeError: 'Series' objects are mutable, thus they cannot be hashed

0 个答案:

没有答案