Python Pandas Trick How to apply a function to more then 1 column

preview_player
Показать описание
How to learn Python for Data science fast
datascience with python
Рекомендации по теме
Комментарии
Автор

Mate, I spent over 4 hours on a function and just achieved the result i wanted to achieve by watching this 8 minutes video... Thank you a lot.
My mistake was using df['column'] instead of having the parameter row. Great work

MM-unwg
Автор

Hmmm, more natural way is to use numpy functions like where or select

For example:
1) We have that df
2) df['result'] = np.where(df['beer'] > df['wine'])

That's all.
Moreover, we can specify what we want to get if condition satisfied or not like that

df['result'] = np.where(df['beer'] > df['wine], 1, 0)

And where condition is satisfied - there will be 1, if not there will be 0. It's like "if" statement.

But if you can just
df['result'] = df[df['beer'] > df['wine]]

Ye, there is a lot of simple ways without apply.

ЕвгенийКрасилов-оо