I have the following data frame and want to:
monthQTY_SOLDand NET_AMT of each unique
I am thinking about this long time, thanks for your question push me to make it .By using agg and if...else
df.groupby(['month', 'UPC_ID'],as_index=False).agg(lambda x : x.sum() if x.dtype=='int64' else x.head(1))
Out[1221]:
month UPC_ID UPC_DSC D_DATE QTY_SOLD NET_AMT
0 2 111 desc1 2017-02-26 2 10
1 2 222 desc2 2017-02-26 3 15
2 2 333 desc3 2017-02-26 1 4
3 3 111 desc1 2017-03-01 5 25