[英]how to convert a dictionary containing iterables as items to a dataframe
我有字典d
d=dict()
d['a']=2
d['b']=3
d['c']=list([1,5,7])
如果我嘗試使用
pd.DataFrame.from_dict(d)
然后我得到
df=
'a' 'b' 'c'
2 3 1
2 3 5
2 3 7
當我想要時:
df=
'a' 'b' 'c'
2 3 [1,5,7]
如何獲得這種行為?
嘗試這個:
df = pd.DataFrame.from_dict(d, orient='index').T
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.