[英]Loading Dictionary into Pandas Dataframe
I am trying to load a python dictionary into a Dataframe. 我正在尝试将python字典加载到Dataframe中。
The structure of the dictionary is unusual, as follows: 字典的结构很不寻常,如下:
a = {('a','b','c'): [0.2,0.3],('a','b','e'): [0.25,0.35]}
Before I converted to Python 3, the following code used to work 在我转换为Python 3之前,以下代码用于工作
b = DataFrame(a.items(),columns=['Systems','stats'])
Now, with Python 3.5, I get the error message: 现在,使用Python 3.5,我收到错误消息:
Error: 错误:
ValueError: DataFrame constructor not properly called! ValueError:未正确调用DataFrame构造函数!
I believe you need convert it to list, or upgrade to last version of pandas 0.25
, then not necessary: 我相信您需要将其转换为列表,或升级到最新版本的pandas 0.25
,然后没有必要:
a = {('a','b','c'): [0.2,0.3],('a','b','e'): [0.25,0.35]}
print (list(a.items()))
[(('a', 'b', 'c'), [0.2, 0.3]), (('a', 'b', 'e'), [0.25, 0.35])]
b = pd.DataFrame(list(a.items()),columns=['Systems','stats'])
print (b)
Systems stats
0 (a, b, c) [0.2, 0.3]
1 (a, b, e) [0.25, 0.35]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.