LernerPython blog, from Reuven Lerner: Pandas 3.1 filter: Selecting rows with a pd.col condition

2 weeks ago 14
Club.noww.in
 Selecting rows with a pd.col condition

Starting with Python Pandas 3.1, use “filter” to apply a condition to rows. So:

( df .loc[ pd.col('passenger_count') > 1 , 'trip_distance'] .mean() )

can now be (the much slower):

( df .filter(cond=pd.col('passenger_count') > 1) ['trip_distance'] .mean() )

The post Pandas 3.1 filter: Selecting rows with a pd.col condition appeared first on LernerPython.

Read Entire Article