Selecting rows in Pandas using .loc and lambda

preview_player
Показать описание
.loc provides us with many ways to select rows and columns from a Pandas data frame. But did you know that you can use lambda to select rows, as well? This can come in handy in a variety of cases, including when you have a long, complex chain of methods in your query. In this video, I show you the basics of using lambda to select specific rows — including an explanation of what "lambda" does for the uninitiated.
Рекомендации по теме
Комментарии
Автор

Great thanks for this amazing video. I learnt a great deal and have more confidence in using lambda now. 😊🙏

eleanortay
Автор

Thanks for the video. I didn't know you could pass a function to '.loc'.

What you said in a comment below about the lambda technique's utility when chaining multiple '.loc' (or presumably other types of manipulations) together makes sense. Otherwise, at least to me, the lambda technique seemed exactly the same as a regular '.loc' expression, albeit with a 'lambda df_:' in front and the dataframe variable name replaced by 'df_'.

There's another reason I could see myself using this in practice: if my dataframe's variable name is long, it's inconvenient to repeat it inside of the '.loc' call. My convention is to do a quick 'df = my_long_df_name' just before, but maybe the lambda technique is more elegant.

jaredclaypoole
Автор

Sorry for misunderstanding: what does lambda do in loc? Is it goes row for a row inside df? And 'df_' here just a noname variable for function?

MrAstonmartin
Автор

Hi.
Why it is not giving the error " df_ is not defined "?
Kindly, guide thanks

RahulJain-fkbu