字典示例:
{'892420643555336193': (8374, 38224),
'892177421306343426': (6181, 32765),
'891815181378084864': (4091, 24675),
'891689557279858688': (8512, 41548),
'891327558926688256': (9219, 39740)}
我想要一个数据框,其中(第一行的示例)
Column A
892420643555336193
Column B
8374
Column C
38224
答案 0 :(得分:1)
您可以创建一个包含字典键和一个字典值的数据框,然后使用numbers
进行组合:
pd.concat
或者,用字典创建一个普通的数据框,转置它,然后重新设置索引(注意顺序已切换):
import pandas as pd
# where d is your dictionary
df = pd.concat((pd.DataFrame(list(d.keys())),pd.DataFrame(list(d.values()))),axis=1)
>>> df
0 0 1
0 892420643555336193 8374 38224
1 892177421306343426 6181 32765
2 891815181378084864 4091 24675
3 891689557279858688 8512 41548
4 891327558926688256 9219 39740
然后您可以根据需要重命名列:
df = pd.DataFrame(d).T.reset_index()
>>> df
index 0 1
0 891327558926688256 9219 39740
1 891689557279858688 8512 41548
2 891815181378084864 4091 24675
3 892177421306343426 6181 32765
4 892420643555336193 8374 38224