I'm using xarray to extract data from a NetCDF file (.nc). I need to extract the 75th percentile value for one of the variables (concentration of chemical) at each time step across a set of dimensions (latitude, longitude, depth). I'm using the below code to do this
df = xr.open_dataset("10y_125_365_concentration.nc")
c_75 = df.concentration.quantile(0.75, dim=('latitude', 'longitude', 'depth'))
The result gives '0' as output for first few time steps before giving specific values of concentration. It appears that the code calculates 75th percentile values across entire array, however, I need to extract 75 percentile values excluding the zeros in the array (the length of the concentration array with values other than 0 changes with time and the number of zero values decreases as time step increases)