Answers for "if condition on multiple columns in pandas"

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
2

pandas create a new column based on condition of two columns

conditions = [
    df['gender'].eq('male') & df['pet1'].eq(df['pet2']),
    df['gender'].eq('female') & df['pet1'].isin(['cat', 'dog'])
]

choices = [5,5]

df['points'] = np.select(conditions, choices, default=0)

print(df)
     gender      pet1      pet2  points
0      male       dog       dog       5
1      male       cat       cat       5
2      male       dog       cat       0
3    female       cat  squirrel       5
4    female       dog       dog       5
5    female  squirrel       cat       0
6  squirrel       dog       cat       0
Posted by: Guest on December-01-2020
0

dataframe isin multiple columns

pd.merge(df2, df1, how='inner')
#         col1  col2
# 0      pizza   boy
# 1      pizza  girls
# 2  ice cream   boy
Posted by: Guest on August-13-2021

Code answers related to "if condition on multiple columns in pandas"

Python Answers by Framework

Browse Popular Code Answers by Language