![](/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.