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
#2
Also posted at https://www.dreamincode.net/forums/topic...pdgrourby/.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Twilio alternative jmair 3 3,893 Feb-08-2024, 01:55 PM
Last Post: Sharmi
  Pillow alternative? kucingkembar 4 867 Jul-27-2023, 10:50 AM
Last Post: Larz60+
  Alternative for Cairosvg? Maryan 0 2,450 Oct-26-2020, 01:27 PM
Last Post: Maryan
  Requesting help with my implementation of depth-first search tigerfuchs 6 2,572 Sep-26-2019, 05:47 AM
Last Post: perfringo
  another alternative to np.interp evelynow 1 2,922 Aug-22-2019, 03:32 PM
Last Post: Larz60+
  Multithreading alternative MartinV279 1 2,778 Aug-01-2019, 11:41 PM
Last Post: scidam
  Requesting help with 3D plotting with quivers Akan2019 1 1,607 May-15-2019, 07:46 AM
Last Post: Akan2019
  Array alternative oldcity 3 3,472 Oct-01-2018, 10:03 PM
Last Post: ichabod801
  If elif else alternative brocq_18 13 12,211 Apr-12-2017, 06:53 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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