Python Forum
Groupby([]).sum() Miscalculation
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Groupby([]).sum() Miscalculation
#1
Hi all, this is my first post so please take it easy! Tongue

The following code is dropping data: e.g. SEC figures is missing "1 Insurance/Annuity Products" should be 2 total and FDIC is missing "2 Residential Mortgage" line items; any ideas what may be wrong? Thanks!

n = df1.groupby(['Year', 'State', 'Regulator', 'Industry','Product', 'Count']).sum()


Output usingcode above:

Output:
Year State Regulator Industry Product Count 2012 Alabama FDIC Depository Institution Debit Card 1 Residential Mortgage 1 OCC Depository Institution Bonds/Notes 1 Commercial Mortgage 1 Credit Card 1 Debit Card 1 3 4 Residential Mortgage 2 Stocks 1 SEC Securities/Futures Insurance/Annuity Products 1 Stocks 1 3
Correct values:

Output:
Year State Industry Regulator Product Count 2012 Alabama Depository Institution FDIC Residential Mortgage 1 2012 Alabama Depository Institution FDIC Residential Mortgage 1 2012 Alabama Depository Institution FDIC Residential Mortgage 1 2012 Alabama Depository Institution FDIC Debit Card 1 Year State Industry Regulator Product Count 2012 Alabama Securities/Futures SEC Insurance/Annuity Products 1 2012 Alabama Securities/Futures SEC Insurance/Annuity Products 1 2012 Alabama Securities/Futures SEC Stocks 3 2012 Alabama Securities/Futures SEC Stocks 1
Reply
#2
just about impossible to say what is wrong without support code.
Please show enough code to support analysis.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to use bfill und groupby under conditions karlito 1 714 Dec-13-2019, 07:03 PM
Last Post: ibreeden
  groupby question smw10c 2 1,891 Mar-29-2017, 11:17 PM
Last Post: smw10c

Forum Jump:

User Panel Messages

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