In a dataset, I need to find how many instances of "mr.","mrs." and "miss." there are. For example:
Obama, Mr. Barack Hussein Obama, Mrs. Michelle LaVaughn Robinson Biden, Mr. Joe Portman, Miss. Natalie
In this expression, it must search after "," and must get "Mr." exactly. In my search code, it also counts "mrs" instead of only "Mr.".
Mr = df.loc[df['Name'].str.contains('Mr.', case=False)]
You can use a regex. The titles are distinctive enough that they should not appear anywhere else.
Mr. 2 Miss. 1 Mrs. 1