Reputation: 317
How can I display only the row where the text contains the word like * AV * e.g 'AV Snow' or 'AV (Some)' or 'Me AV'
# Select Structural status = 'AVAILABLE' or like *AV*
value_list = ['AVAILABLE', '[AV]']
'[AV]' doesnt seem correct
# Grab DataFrame rows where column has certain values
new_df = df[df.STRUCTURALSTATUS.isin(value_list)]
new_df.shape
Upvotes: 4
Views: 9838
Reputation: 826
If you want to use regex patterns, you might want to use str.contains on your serie to filter the DataFrame. Then you can apply a list with the isin function on your result.
Example:
df[df.STRUCTURALSTATUS.str.contains('[AV]')]
Upvotes: 0
Reputation: 164623
Here is one way.
Solution
import pandas as pd
df = pd.DataFrame({'A': ['AV', 'AV Snow', 'Test', 'AV (Some)',
'Nothing', 'Me AV', 'Available', 'NA']})
df = df[df['A'].str.contains('AV', regex=False, case=False, na=False)]
Result
A
0 AV
1 AV Snow
3 AV (Some)
5 Me AV
6 Available
Explanation
regex=False
disables regex as it is not required for your particular task.case=False
makes the search case insensitive.na=False
means you won't see errors if there are unusual types in your series, e.g. non-strings.Upvotes: 13