The new case_when method in Pandas 2.2.0

Опубликовано: 23 Январь 2024
на канале: Python and Pandas with Reuven Lerner
1,435
76

Pandas 2.2.0 includes a new method, case_when. What is it, and how can you use it? I give an overview, with a number of examples.

Note: In my excitement to get this video done, I showed a different example than I had planned for passing a method; the call to str.contains returns a boolean series, and isn't actually a callable.

Here's a simple example of passing a callable, albeit not the most interesting one:

s.case_when(caselist=[(lambda s_: s_.lt(500), 'low'),
(lambda s_: s_.ge(500), 'high')])

The conditions here are lambdas (aka anonymous functions) that are invoked by case_when, rather than boolean series.


Смотрите видео The new case_when method in Pandas 2.2.0 онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Python and Pandas with Reuven Lerner 23 Январь 2024, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 1,435 раз и оно понравилось 76 людям.