Python Forum
requesting help for a faster alternative of pd.groupby - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: requesting help for a faster alternative of pd.groupby (/thread-34218.html)



requesting help for a faster alternative of pd.groupby - zollen - Jul-07-2021

I am new to python. I have two panda dataframes, they need to be merged conditionally.

group= df.groupby(['index1', 'index2'])['counts'].mean()

for index, value in group.items():
    final_df.loc[(final_df['index1'] == index[0]) & 
           (final_df['index2'] == index[1]), 'result'] = value
For small data sets, above code works just fine, but for a very large dataset, the for loop would take many many hours to complete. Is there any alternative for doing the above task much faster?


RE: requesting help for a faster alternative of pd.groupby - ndc85430 - Jul-07-2021

Also posted at https://www.dreamincode.net/forums/topic/421377-requesting-help-for-a-faster-alternative-of-pdgrourby/.