![](/img/trans.png)
[英]Combining data from different rows based on the cell content and creating new columns based on the cell values with pandas and python
[英]Creating columns based on individual values in rows pandas
希望通过有四列的 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
我想创建一个新的 dataframe ,它可以给我所有现有的列,并根据每行 C 列中的当前数字位置创建值为 1 的新列。
喜欢;
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
等等..任何帮助将不胜感激。 我目前正在处理一些 for 循环
让我们试试get_dummies
df=df.join(df.C.str.get_dummies(' ').add_prefix('col'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.