Тёмный

Pandas Where | pd.DataFrame.where() 

Подписаться
Просмотров 6 тыс.
% 83

Pandas Where will replace values where your condition is False. It is useful when you have values that do not meet a criteria, and they need replacing.
We don't often use this function, but it can be a handy one liner instead of iterating through a DataFrame or Series with .apply().
pd.DataFrame.where(cond=condition_to_check, other="Value To Fill")

Опубликовано:

 

16 сен 2020

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 15   
@maamounhajnajeeb209
@maamounhajnajeeb209 Год назад
The explanation is fantastic, thanks
@DataIndependent
@DataIndependent Год назад
Love it - glad it worked out
@danielebaldoni2181
@danielebaldoni2181 2 года назад
Thank you for sharing. Very useful
@DataIndependent
@DataIndependent 2 года назад
My pleasure. Any other videos you'd like to see?
@danielebaldoni2181
@danielebaldoni2181 2 года назад
@@DataIndependent thank you i'm watching data visualizations video. How about clipping data? Like an outlier. There should be a function called clip()
@naismith3529
@naismith3529 3 года назад
Hello, thx for this tutorial. Any possibilities for same things but for 'True'?
@DataIndependent
@DataIndependent 3 года назад
You could just throw a negative sign (- or ~) in front of your condition and flip it. It’ll turn your trues to Falses
@prashantdas3618
@prashantdas3618 3 года назад
couldn't we've just done df[df > 90] = 'A+' for: replace scores above 90 with an 'A+'
@DataIndependent
@DataIndependent 3 года назад
You could have yes! But to be 100% sure I know what my code is doing, I try to be as explicit as possible (using 'where' instead of a blanket '=' sign). Either method works.
@abdillahinassir8297
@abdillahinassir8297 3 года назад
How about a tutorial on sorting, pivoting and filtering
@DataIndependent
@DataIndependent 3 года назад
Nice! Thank you for the suggestion. For sorting: www.dataindependent.com/pandas/pandas-sort-values/ For Filtering: www.dataindependent.com/pandas/pandas-query/ For Pivot: We haven't done a video yet. Thanks for the suggestion!
@pamanjijagadesh5523
@pamanjijagadesh5523 Год назад
your explanation is good, but you are not explained how to replace values with pandas series, please tell me sir.
@DataIndependent
@DataIndependent Год назад
Sorry, I don't understand your question. Do you mean how do you replace a pandas series with another pandas series?
@pamanjijagadesh5523
@pamanjijagadesh5523 Год назад
@@DataIndependent yes
@DataIndependent
@DataIndependent Год назад
@@pamanjijagadesh5523 Oh then you just need to do df['your_first_series'] = df['your_second_series'] and it will be overwritten