【发布时间】:2020-06-08 09:11:12
【问题描述】:
我有一个沿单个维度具有多个坐标的 xarray。在下面的示例中,坐标a 和b 沿维度dim1 定义。我将如何groupby 使用沿相同维度定义的两个坐标?与this question 不同,我不是试图按照不同的维度进行分组,而是一个单一的维度。
import xarray as xr
d = xr.DataArray([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]],
coords={
'a': ('dim1',['A', 'A', 'B', 'B']),
'b': ('dim1',['1', '2', '1', '2']),
'c': ('dim2',['x', 'y', 'z'])
},
dims=['dim1', 'dim2'])
d.groupby(['a','b']) # this gives: TypeError: `group` must be an xarray.DataArray or the name of an xarray variable or dimension
【问题讨论】:
标签: python python-3.x pandas-groupby python-xarray