Bottom Page

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
buran wrote Sep-15-2019, 06:22 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Quote
#2
just about impossible to say what is wrong without support code.
Please show enough code to support analysis.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to use bfill und groupby under conditions karlito 1 443 Dec-13-2019, 07:03 PM
Last Post: ibreeden
  Groupby in pandas with conditional - add and subtract rregorr 2 2,587 Jul-12-2019, 05:17 PM
Last Post: rregorr
  Pandas segmenting groupby average brocq_18 0 748 Jul-11-2018, 10:54 AM
Last Post: brocq_18
  groupby question smw10c 2 1,549 Mar-29-2017, 11:17 PM
Last Post: smw10c

Forum Jump:


Users browsing this thread: 1 Guest(s)