我有一个数据帧如下没有标题。你知道吗
当前测向:
Col 0 Col 1 Col 2 Col3
2345 abcd mobile oneplus
4567 abbb internet explorer
mozilla 2345 cccc dddd
eeee bbbb 1234 hello
我想将digits值(即ID
)作为第一列(列索引0)。你知道吗
如果在任何一行中,数字值移到Col 1
,组合Col 1
和Col2
值并放入Col 1
,然后将Col3
值放入Col2
,然后将下一行的Col0
值作为前一行的Col3
。你知道吗
预期产出如下:
Col 0 Col 1 Col 2 Col3
2345 abcd mobile oneplus
4567 abbbinternet explorer mozilla
2345 ccccdddd eeee bbbb
1234 hello
非常感谢您的帮助!谢谢。。你知道吗
您可以使用
stack
、set_index
和unstack
这样做:输出:
在将这些数据读入熊猫之前,可能更容易进行一些清理。假设您的数据是CSV,这不是最漂亮的代码,但这应该可以做到:
相关问题 更多 >
编程相关推荐