我如何在元组列表和列表之外有数据框的单独列 [英] How can I have separate columns of a dataframe out of list of tuples and a list
本文介绍了我如何在元组列表和列表之外有数据框的单独列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下列表:
l1 = [(1,2),(3,4),(5,6)]
l2 = [7,8,9]
我希望输出为df
df =
c1 c2 c3
0 1 2 7
1 3 4 8
2 5 6 9
到目前为止,我只能将元组分离为
So far I can separate out just the tuple as
df = pd.DataFrame(l1)
这给了我
c1 c2
0 1 2
1 3 4
2 5 6
如上所述,我想处理多个不同形式的列表.
I want to do for multiple lists of different forms as mentioned above.
推荐答案
You could also just use pd.concat
, and concatenate the dataframes resulting from pd.DataFrame(l1)
and pd.Dataframe(l2)
:
df = pd.concat([pd.DataFrame(l1), pd.DataFrame(l2)], axis=1)
>>> df
0 1 0
0 1 2 7
1 3 4 8
2 5 6 9
这篇关于我如何在元组列表和列表之外有数据框的单独列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文