return magdir

def MagRes(group):
    u = np.sum(group['MagViento'] * np.sin(np.deg2rad(group['DirViento'])))
v = np.sum(group['MagViento'] * np.cos(np.deg2rad(group['DirViento'])))
return np.sqrt(u * u + v * v)
How to add a new column to a hierarchical dataframe grouped by groupby