0

I have the below dataframe:

COLA    COLB    COLC
a       cfg     100
b       gdd     100     
c       ert     100
d       yrt     100
a       yui     100
d       ouo     100
a       ooo     100
b       qwe     100

I want to combine all the items in COLA (groupby?) and then sum their values in COLC and end up with

COLA    COLC
a       300
b       200    
c       100
d       200

I'm trying:

df.groupby('COLA').sum('COLC')
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Ari
  • 5,301
  • 8
  • 46
  • 120

1 Answers1

2

The GroupBy object supports column indexing in the same way as the DataFrame, and returns a modified GroupBy object

import pandas as pd
df=pd.read_csv(path)
df.groupby('COLA')['COLC'].sum()
Swati Singh
  • 100
  • 5