'How to groupby year and month for netCDF file in python

So I have a nc file, which has the following variables.

import numpy as np
import pandas as pd
import xarray as xr
import matplotlib.pyplot as plt

[enter image description here][1]

My aim is to get the average value of 'mslp' that groupby both month and year.

I tried the following codes:

da.groupby('time').mean()

and also

 da.groupby('time').mean('mslp')

However, error occurred.

ValueError: cannot reduce over dimensions ['mslp']. expected either '...' to reduce over all dimensions or one or more of Frozen(SortedKeysDict({'lat': 17, 'lon': 1})).

What is the solution for this? Would be so grateful if you can provide me the solution. [1]: https://i.stack.imgur.com/sQDa3.jpg



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source