Filter a Pandas DataFrame Using a List
Python
Data Preprocessing
To use a list to filter a Pandas DataFrame we can make use of the isin function and pass a list of values to keep.
In the example below we pass a list called "values" containing the two values from the Embarked column in our DataFrame that we want to filter for.
1| values = ['Q', 'C'] 2| 3| # df will contain only rows that have either a 'Q' or 'C' in 4| # the Embarked column 5| df = df[df['Embarked'].isin(values)]
4
4
3
3
2
How to Remove Punctuation From Text with Python
Python
Data Preprocessing
Nlp | String | Punctuation
2
2
How to Create Different Aggregations Using GroupBy, Agg & Dictionaries
Python
Data Preprocessing
2
2
2