本文介绍了如何将Pandas中的一列扩展为多列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为标题,我在熊猫中有一列(系列),并且每一行都是类似[0,1,2,3,4,5]的列表.每个列表有6个数字.我想将此列更改为6列,例如,[0,1,2,3,4,5]将变为6列,其中0是第一列,1是第二列,2是第三列,依此类推.我该怎么做?

As the title, I have one column (series) in pandas, and each row of it is a list like [0,1,2,3,4,5]. Each list has 6 numbers. I want to change this column into 6 columns, for example, the [0,1,2,3,4,5] will become 6 columns, with 0 is the first column, 1 is the second, 2 is the third and so on. How can I make it?

推荐答案

不如@jezrael的解决方案那么快.但优雅:-)

Not as fast as @jezrael's solution. But elegant :-)

applypd.Series

df.a.apply(pd.Series)

   0  1  2  3  4  5
0  0  1  2  3  4  5
1  0  1  2  3  4  5

df.a.apply(pd.Series, index=list('abcdef'))

   a  b  c  d  e  f
0  0  1  2  3  4  5
1  0  1  2  3  4  5

这篇关于如何将Pandas中的一列扩展为多列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 18:59