Answers for "conditional filter based on multiple column on another dataframe pandas"

5

filter dataframe multiple conditions

# when you wrap conditions in parantheses, you give order
# you do those in brackets first before 'and'
# AND
movies[(movies.duration >= 200) & (movies.genre == 'Drama')]
Posted by: Guest on March-21-2020
1

filter dataframe by two columns

#tl;dr use the '&' opperator and not the word 'and'
print(df)
OUTPUT
  Name  Age
0  Joe   23
1  Tom   54
2  Joe   34
3  Tom   42
4  Joe   23
5  Tom   54
6  Joe   34
7  Tom   42

tom_and_42 = df[(df["Name"]=="Tom") & (df["Age"]==42)] 

print(tom_and_42)
OUTPUT
  Name  Age
3  Tom   42
7  Tom   42
Posted by: Guest on July-21-2021

Code answers related to "conditional filter based on multiple column on another dataframe pandas"

Python Answers by Framework

Browse Popular Code Answers by Language