Pandas .loc filtering: Replacing lambda with pd.col

Pandas .loc filtering: Replacing lambda with pd.col

Filtering a Python Pandas data frame by the index? Pandas 3 adds pd.col, removing lambda from our .loc expression.

Before:

df.loc[ lambda df_: df_['x'] > df_['w'] ]

Now:

df.loc[ pd.col('x') > pd.col('w') ]

Note: You cannot use pd.col with a series, only a data frame.