Python Forum
What is the better way of avoiding duplicate records after aggregation in pandas ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What is the better way of avoiding duplicate records after aggregation in pandas ?
#1
I want to know the better way of selecting the top revenue generating groups.

This is the data i am using

Here is my code, i want to see which are the top genre that is having high revenue.

import pandas as pd
df=pd.read_csv('Downloads\gpdset\google-play-store-11-2018.csv')
df['Top_revenue']=df.groupby('genre_id')['price'].transform('sum')
df[['genre_id','Top_revenue']].drop_duplicates().sort_values(by=['Top_revenue'],ascending=[False])
I am able to get the correct and intended results, but i feel this is not the right way to do it, because i am doing a aggregation using transform('sum') and again dropping the duplicates, i think this is very bad design, if there is a better way of doing it please do let me know. Thanks in advance.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to retrieve records in a DataFrame (Python/Pandas) that contains leading or trail mmunozjr 3 1,745 Sep-05-2022, 11:56 AM
Last Post: Pedroski55
  Average values on duplicate records chandramouliarun 1 830 Jul-27-2022, 03:13 AM
Last Post: deanhystad
  Class-Aggregation and creating a list/dictionary IoannisDem 1 1,917 Oct-03-2021, 05:16 PM
Last Post: Yoriz
  Avoiding Re-login Goodsayan 0 1,368 Sep-09-2021, 01:53 PM
Last Post: Goodsayan
  How to mark duplicate rows in pandas Mekala 3 2,537 Sep-17-2020, 11:32 PM
Last Post: scidam
  Avoiding too many if's Ted_Toad 6 2,526 Sep-17-2020, 07:18 PM
Last Post: Ted_Toad
  conditional groupby and aggregation on the conditioned group values harrshu 1 2,018 Oct-20-2019, 10:24 AM
Last Post: DeaD_EyE
  Avoiding traceback not through input filtering Mark17 5 2,534 Oct-16-2019, 04:15 PM
Last Post: ichabod801
  Avoiding empty line in writing process csv file go127a 4 9,691 May-10-2019, 01:33 PM
Last Post: go127a
  Aggregation json by nested elements Omri 1 2,515 Sep-05-2018, 04:45 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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