Answers for "select dataframe columns by two conditions"

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
1

python multiple conditions in dataframe column values

df.loc[(df['Salary_in_1000']>=100) & (df['Age']< 60) & (df['FT_Team'].str.startswith('S')),['Name','FT_Team']]
Posted by: Guest on August-25-2021

Code answers related to "select dataframe columns by two conditions"

Python Answers by Framework

Browse Popular Code Answers by Language