Efficiently mask and calculate means for multiple groups in `xr.Dataset` xarray

I have two xr.Dataset objects. One is a continuous map of some variable (here precipitation). The other is a categorical map of a set of regions [‘region_1’, ‘region_2’, ‘region_3’, ‘region_4’]. I want to calculate the mean precip in each region at each timestep by masking by region/time and then outputting a dataframe looking like the […]