Created
August 8, 2020 02:57
-
-
Save SolClover/765271ce0f21a4353997bc3714b7295d to your computer and use it in GitHub Desktop.
Filter Pandas DataFrame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Filter on one condition | |
new_df=df[df['Col_A']>=6] | |
# Filter on multiple conditions using AND | |
new_df=df[(df['Col_A']>=6) & (df['Col_B']==5)] | |
# Filter on multiple conditions using OR | |
new_df=df[(df['Col_A']>=6) | (df['Col_B']==1)] | |
# Create a list and use isin to filter | |
filter_list=['1.apple', '3.pear'] | |
new_df=df[df['fruit'].isin(filter_list)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment