Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # pandas isin using join to create regex for multiple values
- import pandas as pd
- values = ['cat', 'dog', 'hamster']
- # creates bool column that returns True if each element in the DataFrame is contained in values
- df['isin_example'] = (df['target_col'].str.contains('|'.join(values), case=False))
- # Same example but with or 'pig' clause
- df['isin_example'] = (df['target_col'].str.contains('|'.join(words), case=False)) | (df['12_Work Location'].str.contains('pig', case=False))
Advertisement
Add Comment
Please, Sign In to add comment