0

I am quite new to pandas , this my data frame

name quantity weightage type
AAPL   10      20.0     TECH
FORD   20      12.0     AUTO 
AMZN   15      10.0     TECH
TSLA   20      5.0      AUTO

op data frame should be, grouped by tech with sum of quantity and weightage,

name  quantity  weightage
TECH   25        30.0
AUTO   40        17.0 


    
massu1000
  • 209
  • 2
  • 10

1 Answers1

0

Use the pandas.DataFrame.groupby method to split the data frame according to the values in the type column, select quantity and weightage columns and sum over them:

df.groupby('type')[['quantity', 'weightage']].sum()
Flursch
  • 483
  • 2
  • 4