Answers for "filter 2 columns pandas"

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 "filter 2 columns pandas"

Python Answers by Framework

Browse Popular Code Answers by Language