recalculate mean considering each count

  dataframe, group-by, pandas, python

if the dataframe is given as below

index yearmon   college major   gpa     num
0     20140401  1       a       3.36    29
1     20180401  2       b       2.63    48
2     20160401  3       c       3.23    55
3     20170401  4       d       4.22    1
4     20140401  3       b       3.72    72

which gives the average gpa of each year, each college, each major.

i want to make a new data set as average gpa only considering the major.

for example for major b, there is 2 data in different time,

so i have to make a new
gpa average considering the num (number of students)

i have tried groupby function, but it only makes average as they have same num count (not considering num variable)

is there way to solve this problem?

Source: Python Questions