1

I've checked the docs (https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.eq.html)

I'm thinking something like below where I can use and re.I to ingnore case or use any other flag for that matter.

df.column.eq('Male').sum()

1 Answers1

1

You can use the Series.str.contains function with case=False argument, ^Male$ as regex pattern and the regex=True argument:

df['column'].str.contains('^Male$', case=False, regex=True).sum()

See the Series.str.contains documentation.

Also, see What do ^ and $ mean in a regular expression?

Wiktor Stribiżew
  • 561,645
  • 34
  • 376
  • 476
  • So in df .contains, `regex=True` is the default, not necessary, that's what I was trying to find out, thanks for the documentation link – gseattle May 08 '22 at 00:14