# Xarray DataArray resample missing values result in zeros

**URL:** <https://discourse.pangeo.io/t/xarray-dataarray-resample-missing-values-result-in-zeros/1727>\
**Category:** Science\
**Created:** [September 2, 2021, 4:02am UTC](https://discourse.pangeo.io/t/xarray-dataarray-resample-missing-values-result-in-zeros/1727 "2021-09-02T04:02:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![WilcoT](https://avatars.discourse-cdn.com/v4/letter/w/7c8e57/32.png) [@WilcoT](https://discourse.pangeo.io/u/WilcoT)\
**Post date:** [September 2, 2021, 4:02am UTC](https://discourse.pangeo.io/t/xarray-dataarray-resample-missing-values-result-in-zeros/1727/1 "2021-09-02T04:02:00Z")

</div>

Hi,

I have an xarray DataArray with dimensions time, y, and x. Time is in datetime64[ns] format with an hourly frequency. Part of the array contain missing values (np.nan), as they are not part of the study area. These are the same for every time-step. Now I like to resample this to daily grids using:

p = d[‘prec’].resample(time=‘1D’, skipna=True).sum()

However, all the cells that had np.nan in the original DataArray now have a value of zero after resampling. Why are these not kept at NaN? Changing skipna to False does not seem to make a difference.

Anyone any suggestions? Or is this a bug?

Cheers,  
Wilco

---

<div class="post-metadata">

**Author:** ![TomAugspurger](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.pangeo.io/tomaugspurger/32/21_2.png) [@TomAugspurger](https://discourse.pangeo.io/u/TomAugspurger)\
**Post date:** [September 2, 2021, 1:46pm UTC](https://discourse.pangeo.io/t/xarray-dataarray-resample-missing-values-result-in-zeros/1727/2 "2021-09-02T13:46:11Z")

</div>

If xarray is the same as pandas here, which I think it use, you want the `min_count=1` keyword

```auto
min_count : int, default: None
    The required number of valid values to perform the operation. If
    fewer than min_count non-NA values are present the result will be
    NA. Only used if skipna is set to True or defaults to True for the
    array's dtype. New in version 0.10.8: Added with the default being
    None. Changed in version 0.17.0: if specified on an integer array
    and skipna=True, the result will be a float array.

```

There’s some ambiguity about whether the sum([]) should be 0 or NA. Most systems define it as 0.

---

<div class="post-metadata">

**Author:** ![WilcoT](https://avatars.discourse-cdn.com/v4/letter/w/7c8e57/32.png) [@WilcoT](https://discourse.pangeo.io/u/WilcoT)\
**Post date:** [September 2, 2021, 9:52pm UTC](https://discourse.pangeo.io/t/xarray-dataarray-resample-missing-values-result-in-zeros/1727/3 "2021-09-02T21:52:25Z")

</div>

Perfect, that works like a charm. Thanks for this easy solution:

p = d.resample(time=_‘1D’_).sum(min\_count=1)

Cheers.

Wilco
