Pandas.core.groupby.dataframegroupby.idxmin() Is Very Slow , How Can I Make My Code Faster?
i am trying to do same action as SQL group by and take min value : select id,min(value) ,other_fields... from table group by ('id') i tried : dfg = df.groupby('id', sort=False) i
Solution 1:
use alternative with DataFrame.sort_values
and DataFrame.drop_duplicates
:
df1 = df.sort_values(by=['value']).drop_duplicates('id', keep='first')
Post a Comment for "Pandas.core.groupby.dataframegroupby.idxmin() Is Very Slow , How Can I Make My Code Faster?"