I have a dataframe as below
username
NA
NA
NA
['Bob']
['']
['']
['Meril']
['Aston']
['Meril Aston']
I need all the rows which has Bob, Meril and Aston or Meril Aston or Bob Aston....all combinations.
I tried
df.username.str.extract(r"\['Bob.*|['Meril.*|['Aston.*")
It not working
CodePudding user response:
Try this:
subset = df[df.username.astype('str').str.contains('Bob|Meril|Aston').fillna(False)]
Output:
>>> subset
username
3 ['Bob']
6 ['Meril']
7 ['Aston']
8 ['Meril Aston']