Extracting Information From Pandas Dataframe
I have the below dataframe. I want to build a rule engine to extract the tokens where the pattern is like Eg. 'UNITED STATES' .What is the best way to do it ? Is there anything li
Solution 1:
You may want to use the contains
string method, which takes a regex argument by default. For example
mask = df['WORD_TOKEN'].str.contains('(UNITED|STATES)')
print(df[mask])
This will match anything containing "united" or "states".
Post a Comment for "Extracting Information From Pandas Dataframe"