home / github / issues

Menu
  • GraphQL API
  • Search all tables

issues: 469633509

This data as json

id node_id number title user state locked assignee milestone comments created_at updated_at closed_at author_association active_lock_reason draft pull_request body reactions performed_via_github_app state_reason repo type
469633509 MDU6SXNzdWU0Njk2MzM1MDk= 3141 calculating cumsums on a groupby object 21049064 closed 0     6 2019-07-18T08:21:57Z 2022-07-20T01:31:37Z 2022-07-20T01:31:37Z NONE      

How do I go about calculating cumsums on a groupby object?

I have a Dataset that looks as the following: ```python lat = np.linspace(-5.175003, 5.9749985, 224) lon = np.linspace(33.524994, 42.274994, 176) time = pd.date_range(start='1981-01-31', end='2019-04-30', freq='M') data = np.random.randn(len(time), len(lat), len(lon)) dims = ['time', 'lat', 'lon'] coords = {'time': time, 'lat': lat, 'lon': lon}

ds = xr.Dataset({'precip': (dims, data)}, coords=coords)

Out[]: <xarray.Dataset> Dimensions: (lat: 224, lon: 176, time: 460) Coordinates: * time (time) datetime64[ns] 1981-01-31 1981-02-28 ... 2019-04-30 * lat (lat) float64 -5.175 -5.125 -5.075 -5.025 ... 5.875 5.925 5.975 * lon (lon) float64 33.52 33.57 33.62 33.67 ... 42.12 42.17 42.22 42.27 Data variables: precip (time, lat, lon) float64 0.006328 0.2969 1.564 ... 0.6675 2.32 ```

I need to groupby year and calculate the cumsum for each year. That way I will have a value for each month (timestep) and each pixel (lat - lon pair).

But the cumsum operation doesn't work on a groupby object ```python ds.groupby('time.year').cumsum(dim='time')

Out[]:

AttributeError Traceback (most recent call last) <ipython-input-12-dceee5f5647c> in <module> 9 display(ds_) 10 ---> 11 ds_.groupby('time.year').cumsum(dim='time')

AttributeError: 'DatasetGroupBy' object has no attribute 'cumsum' ```

Is there a work around?

``` INSTALLED VERSIONS


commit: None python: 3.7.0 | packaged by conda-forge | (default, Nov 12 2018, 12:34:36) [Clang 4.0.1 (tags/RELEASE_401/final)] python-bits: 64 OS: Darwin OS-release: 18.2.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: en_US.UTF-8 LANG: en_US.UTF-8 LOCALE: en_US.UTF-8 libhdf5: 1.10.4 libnetcdf: 4.6.2

xarray: 0.12.2 pandas: 0.24.2 numpy: 1.16.4 scipy: 1.3.0 netCDF4: 1.5.1.2 pydap: None h5netcdf: None h5py: 2.9.0 Nio: None zarr: None cftime: 1.0.3.4 nc_time_axis: None PseudonetCDF: None rasterio: 1.0.17 cfgrib: 0.9.7 iris: None bottleneck: 1.2.1 dask: 1.2.2 distributed: 1.28.1 matplotlib: 3.1.0 cartopy: 0.17.0 seaborn: 0.9.0 numbagg: None setuptools: 41.0.1 pip: 19.1 conda: None pytest: 4.5.0 IPython: 7.1.1 sphinx: 2.0.1 ```

{
    "url": "https://api.github.com/repos/pydata/xarray/issues/3141/reactions",
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  completed 13221727 issue

Links from other tables

  • 1 row from issues_id in issues_labels
  • 6 rows from issue in issue_comments
Powered by Datasette · Queries took 1.239ms · About: xarray-datasette