计算 pandas 中的非零列值
count non zero column values in pandas
在 pandas 数据框中,
我需要一个计数非零出现的计数列
请帮助..
尝试
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
在 pandas 数据框中, 我需要一个计数非零出现的计数列
请帮助..
尝试
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