AnsweredAssumed Answered

GroupBy 2 columns and keep all fields

Question asked by jamesfreddyc on Aug 3, 2017
Latest reply on Aug 4, 2017 by jamesfreddyc

Edit: here's the current code I've got so far:

 

itsct_nparr = arcpy.da.FeatureClassToNumPyArray(prItsct, ['FID_preproc','NAME','Shape_Area'])

#create a pandas DataFrame objects from the NumPy arrays
itsct_df = DataFrame(itsct_nparr, columns=['FID_preproc','NAME','Shape_Area'])
maxarea = itsct_df.groupby(['FID_preproc','NAME'], as_index=False).max()
maxarea.to_csv(csvout)
del itsct_nparr

 

I need to come up with a solution that allows me to summarize an input table, performing a GroupBy on 2 columns ("FID_preproc" and "Shape_Area") and keep all of the fields in the original table in the output/result.  From there I'll be joining that result with another table and calculating a field using the NAME column.

 

From the example, I need to maintain the FID_preproc, and NAME fields (see the desired result).  GroupBy on FID_preproc and MAX(Shape_Area).

 

Any method is acceptable (numpy, pandas, summarize table, da.SearchCursor, etc.) -- whatever you have I can use!

 

Input:
FID_preprocNAMEShape_Area
1340A25952.35775
1341A118099.5219
1341B305220.1244
1342A12053.13585
Desired Result:
FID_preprocNAMEShape_Area
1340A25952.35775
1341B305220.1244
1342A12053.13585

Outcomes