[英]how to turn a list of 2 lists into a 2 columns df in pandas
I have this list (which is created using append function twice): 我有此列表(使用附加函数两次创建的列表):
['2017-04-03.csv', 108.0, '2017-04-04.csv', -12.0]
(it's much longer and length can very) and when using results = pd.DataFrame({'col':results})
I get the following: (它的长度和长度可能要长得多),并且当使用
results = pd.DataFrame({'col':results})
我得到以下信息:
col
0 2017-04-03.csv
1 108
2 2017-04-04.csv
3 -12
I am looking to get: 我希望得到:
col
2017-04-03.csv 108
2017-04-04.csv -12
I checked the solutions offered here , here and here but they all not work as I expect/need. 我检查了此处 , 此处和此处提供的解决方案,但它们都无法按我的期望/要求工作。 thanks
谢谢
Slicing is your friend - 切片是您的朋友-
pd.DataFrame(results[1::2], index=results[::2], columns=['col'])
col
2017-04-03.csv 108.0
2017-04-04.csv -12.0
Even indexed elements form the index, and odd indexed elements form the column values. 偶数索引元素构成索引,奇数索引元素构成列值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.