简体   繁体   English

基于行 pandas 中的单个值创建列

[英]Creating columns based on individual values in rows pandas

Looking to simplify a huge dataset via pandas which has four columns,希望通过有四列的 pandas 简化庞大的数据集,

        Time        A   B     C
    27/5/2020 1:30 -90 -12  0 2 3 5 6
    27/5/2020 1:35 -90 -11  0 2 3 4 6 7 8
    27/5/2020 1:40 -80 -12  2 4 5 6 9 12 15

I want to create a new dataframe which can give me all the existing columns and create new columns with value 1 based on the current numbers positions in columns C for each row.我想创建一个新的 dataframe ,它可以给我所有现有的列,并根据每行 C 列中的当前数字位置创建值为 1 的新列。

Like;喜欢;

Time             A   B      C             Col1 Col2 Col3 Col4 Col5 Col6 Col7
27/5/2020 1:30 -90 -12  0 2 3 5 6          1   0    1    1    0     1   1

and so on.. any help will be much appreciated.等等..任何帮助将不胜感激。 I am working through some for loops at the moment我目前正在处理一些 for 循环

Let us try get_dummies让我们试试get_dummies

df=df.join(df.C.str.get_dummies(' ').add_prefix('col'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM