imagine i have a column days
days |
---|
190 |
567 |
55 |
I want to create a new column based on the condition that df['new_colum'] =
if day < 180:
print(y)
elif( days >180 & < 365):
print(d)
else:
print(h)
how do i do this in python and any alternative for if condition
CodePudding user response:
You can use df.apply
:
df['new_col'] = df.days.apply(lambda x: y if x < 180 else (d if 180 < x < 365 else h))