[英]Count occurrences of certain string in entire pandas dataframe
I have following dataframe in pandas我在熊猫中有以下数据框
C1 C2 C3
10 a b
10 a b
? c c
? ? b
10 a b
10 ? ?
I want to count the occurrences of ?
我想计算
?
in all the columns在所有列中
My desired output is column wise sum of occurrences我想要的输出是按列出现的总和
Use:用:
m=df.eq('?').sum()
pd.DataFrame([m.values],columns=m.index)
C1 C2 C3
0 2 2 1
Or better :或更好 :
df.eq('?').sum().to_frame().T #thanks @user3483203
C1 C2 C3
0 2 2 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.