How can I calculate skewness via Xarray

Viewed 179

I found the amazing capability of xarray to perform variable resampling and mean, and standard deviation calculations.

Is there a direct way to calculate skewness after temporal resampling of data just like with the .mean() method?

Thanks

1 Answers

You can use xarray.DataArray.reduce() setting the func argument to scipy.stats.skew:

import scipy.stats
import xarray as xr

airtemps = xr.tutorial.load_dataset("air_temperature")
temp_skewness = airtemps.air.resample(time="1M"
                                      ).reduce(func=scipy.stats.skew,
                                               dim="time")
Related