【发布时间】:2016-09-24 23:38:42
【问题描述】:
如何将列表对象转换为具有定义格式的 Pandas Dataframe?
打印列表有这个输出(Jupyter):
(u'variable', price threshold
0 13.5 100.0
1 10.0 NaN)
(u'standard', price threshold
0 12.5 300.0
1 11.0 NaN)
(u'fixed', price threshold
0 14.5 250.0
1 10.1 200.0
2 9.0 NaN)
(u'standing-charge', price
0 9)
转换为 Pandas 数据框:
0 1
0 variable price threshold 0 13.5 100.0 1 10...
1 standard price threshold 0 12.5 300.0 1 11...
2 fixed price threshold 0 14.5 250.0 1 10...
3 standing-charge price 0 9
我需要:
type price threshold
variable 13.5 100
variable 10.0 NaN
...
请帮忙;)
【问题讨论】:
-
这些列表中的元素是什么?数据帧?
-
哦,你DataFrame的索引必须是唯一的,所以你的
I need是不可能的。 -
解析json文件的输出:rows_list = [] for index, row in ds.iterrows(): a = {} a = row['plan'], json_normalize(row['rates' ]) rows_list.append(a) 打印 rows_list
-
type(rows_list) 是列表
-
如何解析这种格式?还没见过类似的格式。
标签: python list pandas dataframe