Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python xarray的loc API给出了KeyError:“;并非在索引“中找到的所有值”;_Python_Pandas_Indexing_Python Xarray - Fatal编程技术网

Python xarray的loc API给出了KeyError:“;并非在索引“中找到的所有值”;

Python xarray的loc API给出了KeyError:“;并非在索引“中找到的所有值”;,python,pandas,indexing,python-xarray,Python,Pandas,Indexing,Python Xarray,我对xarray的loc API有问题。我试图选择满足特定条件的数据。以下是一个可复制的示例: import xarray as xr da = xr.tutorial.load_dataset('air_temperature').air mask = 100*xr.ones_like(da[0]) da[0].loc[da[0]<mask] 将xarray作为xr导入 da=xr.tutorial.load_数据集(“空气温度”).air mask=100*xr.ones\u lik

我对xarray的loc API有问题。我试图选择满足特定条件的数据。以下是一个可复制的示例:

import xarray as xr
da = xr.tutorial.load_dataset('air_temperature').air
mask = 100*xr.ones_like(da[0])
da[0].loc[da[0]<mask]
将xarray作为xr导入
da=xr.tutorial.load_数据集(“空气温度”).air
mask=100*xr.ones\u like(da[0])
da[0].loc[da[0]3 da[0].loc[da[0]196返回self.data_array.sel(**键)
197
198 def\uuuu setitem\uuuuu(self、key、value)->无:
sel中的~/miniconda3/envs/employ/lib/python3.7/site-packages/xarray/core/dataarray.py(self、索引器、方法、公差、下降、**索引器)
1045方法=方法,
1046公差=公差,
->1047**索引器
1048         )
1049从临时数据集(ds)返回自我
sel中的~/miniconda3/envs/employ/lib/python3.7/site-packages/xarray/core/dataset.py(self、索引器、方法、公差、删除、**索引器)
1998索引器=索引器或索引器(索引器,索引器,索引器,“sel”)
1999位置索引器,新索引=重新映射标签索引器(
->2000 self,索引器=索引器,方法=方法,公差=公差
2001         )
2002结果=self.isel(索引器=位置索引器,下降=下降)
重新映射标签索引器中的~/miniconda3/envs/emble/lib/python3.7/site-packages/xarray/core/coordinates.py(对象、索引器、方法、公差、**索引器)
390
391位置索引器,新索引=索引。重新映射标签索引器(
-->392 obj,v_索引器,方法=方法,公差=公差
393     )
394#将索引器的坐标连接到位置索引器
重新映射标签索引器中的~/miniconda3/envs/emble/lib/python3.7/site-packages/xarray/core/index.py(数据对象、索引器、方法、公差)
259 coords\u dtype=数据对象coords[dim].dtype
260 label=可能为协调类型(label,协调类型)
-->261 idxr,新的\u idx=转换\u标签\u索引器(索引、标签、尺寸、方法、公差)
262位置索引器[dim]=idxr
263如果new_idx不是None:
转换标签索引器中的~/miniconda3/envs/emble/lib/python3.7/site-packages/xarray/core/index.py(索引、标签、索引名称、方法、公差)
191索引器=获取索引器(索引、标签、方法、公差)
192如果np.有(索引器<0):
-->193 raise KeyError(“在索引%r”%index\u name中未找到所有值)
194返回索引器,新索引
195
KeyError:“在索引'lat'中未找到所有值”
由于
掩码
在尺寸和坐标方面与xarray.DataArray
da
完全相同,我认为这个错误没有意义……我是否遗漏了什么,或者这可能是一个错误

提前感谢您的帮助

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-238-75b6b6f544d4> in <module>
      1 da = xr.tutorial.load_dataset('air_temperature').air
      2 mask = 100*xr.ones_like(da[0])
----> 3 da[0].loc[da[0]<mask]

~/miniconda3/envs/ensemble/lib/python3.7/site-packages/xarray/core/dataarray.py in __getitem__(self, key)
    194             labels = indexing.expanded_indexer(key, self.data_array.ndim)
    195             key = dict(zip(self.data_array.dims, labels))
--> 196         return self.data_array.sel(**key)
    197 
    198     def __setitem__(self, key, value) -> None:

~/miniconda3/envs/ensemble/lib/python3.7/site-packages/xarray/core/dataarray.py in sel(self, indexers, method, tolerance, drop, **indexers_kwargs)
   1045             method=method,
   1046             tolerance=tolerance,
-> 1047             **indexers_kwargs
   1048         )
   1049         return self._from_temp_dataset(ds)

~/miniconda3/envs/ensemble/lib/python3.7/site-packages/xarray/core/dataset.py in sel(self, indexers, method, tolerance, drop, **indexers_kwargs)
   1998         indexers = either_dict_or_kwargs(indexers, indexers_kwargs, "sel")
   1999         pos_indexers, new_indexes = remap_label_indexers(
-> 2000             self, indexers=indexers, method=method, tolerance=tolerance
   2001         )
   2002         result = self.isel(indexers=pos_indexers, drop=drop)

~/miniconda3/envs/ensemble/lib/python3.7/site-packages/xarray/core/coordinates.py in remap_label_indexers(obj, indexers, method, tolerance, **indexers_kwargs)
    390 
    391     pos_indexers, new_indexes = indexing.remap_label_indexers(
--> 392         obj, v_indexers, method=method, tolerance=tolerance
    393     )
    394     # attach indexer's coordinate to pos_indexers

~/miniconda3/envs/ensemble/lib/python3.7/site-packages/xarray/core/indexing.py in remap_label_indexers(data_obj, indexers, method, tolerance)
    259             coords_dtype = data_obj.coords[dim].dtype
    260             label = maybe_cast_to_coords_dtype(label, coords_dtype)
--> 261             idxr, new_idx = convert_label_indexer(index, label, dim, method, tolerance)
    262             pos_indexers[dim] = idxr
    263             if new_idx is not None:

~/miniconda3/envs/ensemble/lib/python3.7/site-packages/xarray/core/indexing.py in convert_label_indexer(index, label, index_name, method, tolerance)
    191             indexer = get_indexer_nd(index, label, method, tolerance)
    192             if np.any(indexer < 0):
--> 193                 raise KeyError("not all values found in index %r" % index_name)
    194     return indexer, new_index
    195 

KeyError: "not all values found in index 'lat'"