Python怎么转换Dictionary为DataFrame
1个回答
展开全部
转换方法:
import json
import pandas as pd
db = json.loads(open('pruItems.json', 'r').read())
pieces = []
for d in db:
if d['data']:
df = pd.DataFrame(d['data'])
df.columns = ['date', 'bid', 'ask']
df = df.set_index('date')
pieces.append(df)
df = pd.concat(pieces, axis=1, keys=[d['fund'] for d in db])
print df
TGC FEF FAF
bid ask bid ask bid ask
date
18/06/2013 34.8400 34.8400 14.9179 14.9179 6.6780 6.6780
17/06/2013 34.4900 34.4900 14.8712 14.8712 6.6510 6.6570
import json
import pandas as pd
db = json.loads(open('pruItems.json', 'r').read())
pieces = []
for d in db:
if d['data']:
df = pd.DataFrame(d['data'])
df.columns = ['date', 'bid', 'ask']
df = df.set_index('date')
pieces.append(df)
df = pd.concat(pieces, axis=1, keys=[d['fund'] for d in db])
print df
TGC FEF FAF
bid ask bid ask bid ask
date
18/06/2013 34.8400 34.8400 14.9179 14.9179 6.6780 6.6780
17/06/2013 34.4900 34.4900 14.8712 14.8712 6.6510 6.6570
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询