简体   繁体   中英

Filter- required values from nested Dictionary in Python 3.6

I want to fetch some free data from https://coinmetrics.io/ for academic assignment.

I was trying to retrieve only the id and list of metrics for each id from this URL

I want to save results in DataFrame with columns id and metrics

Response = requests.get('https://community-api.coinmetrics.io/v2/asset_info')
Data_API = json.loads(Response.content.decode('utf-8'))

Use json.json_normalize :

Response = requests.get('https://community-api.coinmetrics.io/v2/asset_info')
from pandas.io.json import json_normalize

df = json_normalize(json.loads(Response.content.decode('utf-8'))['assetsInfo'],'metrics','id')
df.columns = ['metrics', 'id']

print (df.head(100))

            metrics    id
0         AdrActCnt   ada
1            BlkCnt   ada
2       BlkSizeByte   ada
...
...
27  TxTfrValMeanNtv   ada
28  TxTfrValMeanUSD   ada
29   TxTfrValMedNtv   ada
..              ...   ...
70          SplyCur  aion
71            TxCnt  aion
72            TxTfr  aion
...
...
81    VtyDayRet180d  aion
82     VtyDayRet30d  aion
83     VtyDayRet60d  aion
84        AdrActCnt   ant
...
...
90            TxTfr   ant
91   TxTfrValAdjNtv   ant
92  TxTfrValMeanNtv   ant
...
...
97        IssTotNtv   bat
98        IssTotUSD   bat
99           NVTAdj   bat

[100 rows x 2 columns]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM