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
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.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With