News

New paper!

Thursday, January 10, 2019

Choosing rows with complex criteria 2

With df, Pandas DataFrame, how do I select rows whose elements in a column are strings containing a specific string?
Conditions:
1. if string in a row of a column contains "A"
>>> df.loc[df.col_name.str.contains(r'(A)')]

2. if string in a row of a column contains "A" or "B"
>>> df.loc[df.col_name.str.contains(r'(A|B)')]