Python Forum
requesting help for a faster alternative of pd.groupby
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
requesting help for a faster alternative of pd.groupby
#1
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?
Reply


Messages In This Thread
requesting help for a faster alternative of pd.groupby - by zollen - Jul-07-2021, 05:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Requesting help with my implementation of depth-first search tigerfuchs 6 3,836 Sep-26-2019, 05:47 AM
Last Post: perfringo
  Requesting help with 3D plotting with quivers Akan2019 1 2,288 May-15-2019, 07:46 AM
Last Post: Akan2019

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020