

在熊貓資料框中,我需要一個計數非零出現次數的列
請幫忙..
uj5u.com熱心網友回復:
嘗試
df['Count'] = df.filter(regex='col\d').ne(0).sum(axis=1)
print(df)
group_col col1 col2 col3 Count
0 group1 23 0 32 2
1 group2 1 1 38 3
2 group3 0 9 97 2
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/476531.html
下一篇:成對輸出傳遞字母的函式
