【发布时间】:2021-06-09 16:26:31
【问题描述】:
我有两个 DataArray 对象,分别称为“A”和“B”。
除了Latitude 和Longitude,它们都有一个time 维度表示每日数据。 A 的时间坐标小于B。
A的时间维度:
<xarray.DataArray 'time' (time: 1422)>
array(['2015-03-30T00:00:00.000000000', '2015-06-14T00:00:00.000000000',
'2015-06-16T00:00:00.000000000', ..., '2019-08-31T00:00:00.000000000',
'2019-09-01T00:00:00.000000000', '2019-09-02T00:00:00.000000000'],
dtype='datetime64[ns]')
Coordinates:
* time (time) datetime64[ns] 2015-03-30 2015-06-14 ... 2019-09-02
B的时间维度:
<xarray.DataArray 'time' (time: 16802)>
array(['1972-01-01T00:00:00.000000000', '1972-01-02T00:00:00.000000000',
'1972-01-03T00:00:00.000000000', ..., '2017-12-29T00:00:00.000000000',
'2017-12-30T00:00:00.000000000', '2017-12-31T00:00:00.000000000'],
dtype='datetime64[ns]')
Coordinates:
* time (time) datetime64[ns] 1972-01-01 1972-01-02 ... 2017-12-31
显然,A 的 time 维度是 B 的 time 维度的子集。我想使用 A 中的所有 time 标签从 B 中选择数据。由于 A 中的时间不连续,我认为 slice 不合适。所以我尝试使用sel。
B_sel = B.sel(time=A.time)
我收到一个错误:KeyError: "not all values found in index 'time'"
【问题讨论】:
标签: python pandas numpy python-xarray