filter dataframe by two columns

Solutions on MaxInterview for filter dataframe by two columns by the best coders in the world

showing results for - "filter dataframe by two columns"
Karl
21 Oct 2019
1#tl;dr use the '&' opperator and not the word 'and'
2print(df)
3OUTPUT
4  Name  Age
50  Joe   23
61  Tom   54
72  Joe   34
83  Tom   42
94  Joe   23
105  Tom   54
116  Joe   34
127  Tom   42
13
14tom_and_42 = df[(df["Name"]=="Tom") & (df["Age"]==42)] 
15
16print(tom_and_42)
17OUTPUT
18  Name  Age
193  Tom   42
207  Tom   42