[英]Count number of cells satisfying a condition in pandas dataframe column
Hi I have following dataframe 嗨,我有以下数据框
Name Gender Age
ABC M 21
C-DF F 24
I have to count the number of cells having a dash in them. 我必须计算其中带有破折号的单元格的数量。 I used the regular expression and wrote the code written below
我使用了正则表达式并编写了下面的代码
df[df['Name'] == r'-+'].sum()
The output that I am getting is. 我得到的输出是。 I don't understand what mistake did I do or if I wrote the wrong command.
我不明白我做了什么错误,或者我写错了命令。
Name 0.0
Gender 0.0
Age 0.0
dtype: float64
Please help. 请帮忙。 Thanks.
谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.