Python Forum
SORTED.group by and count average of two columns [ sum of col 1 / sum of col 2 ]
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SORTED.group by and count average of two columns [ sum of col 1 / sum of col 2 ]
#2
Solved.
filtered_df["RPM"] = filtered_df["Rate"]/filtered_df["Miles"].groupby(filtered_df["PuState"]).transform('mean')
Turns out i solved it by removing ()

EDIT: No , it makes incorrect calculations

EDIT#2 - sorted.
filtered_df["StateRate"] = filtered_df["Rate"].groupby(filtered_df["PuState"]).transform('mean')
filtered_df["StateRPM"] = filtered_df["StateRate"]/filtered_df["Miles"].groupby(filtered_df["PuState"]).transform('mean')
Reply


Messages In This Thread
RE: group by and count average of two columns [ sum of col 1 / sum of col 2 ] in Pandas - by BSDevo - Oct-23-2023, 09:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Remove extra count columns created by pandas groupby spyf8 1 2,758 Feb-10-2021, 09:19 AM
Last Post: Naheed
  Merging sorted dataframes using Pandas Robotguy 1 2,237 Aug-12-2020, 07:11 PM
Last Post: jefsummers
  How to group variables & check correlation of group variables wrt single variable SriRajesh 2 3,003 May-23-2018, 03:01 PM
Last Post: SriRajesh

Forum Jump:

User Panel Messages

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