...

/

Filtering with Function and .loc

Filtering with Function and .loc

See filtering with function and .loc in DataFrames.

We'll cover the following...

Please be aware that we can pass in a boolean array and a function into loc. Here, we select rows with Average_rank less than ten and the first three columns:

Press + to interact
print(pres
.loc[pres.Average_rank < 10, lambda df_: df_.columns[:3]]
)

An advantage of passing a function into loc is that the function will receive the ...