[英]How to access the data variable values of a bound method mapping.values of xarray.Dataset in Python
how can I access the data variable values of a bound method mapping.values of xarray.Dataset, what is the correct syntax:如何访问 xarray.Dataset 的绑定方法 mapping.values 的数据变量值,正确的语法是什么:
I would need to retrieve the pm2p5_conc Data variable:我需要检索 pm2p5_conc 数据变量:
pmScatter["pm25"].values
array([<bound method Mapping.values of <xarray.Dataset>
Dimensions: ()
Coordinates:
level float32 0.0
time timedelta64[ns] 00:00:00
longitude float64 2.352
latitude float64 48.86
Data variables:
pm2p5_conc float64 26.23
Attributes:
title: PM25 Air Pollutant FORECAST at 8 levels
institution: Data produced by Meteo France
source: Data from ENSEMBLE model
history: Model ENSEMBLE FORECAST
FORECAST: Europe, 20210325-20210327+[0H_0H]
summary: ENSEMBLE model hourly FORECAST of PM25 concentration at 8 l...
project: MACC-RAQ (http://macc-raq.gmes-atmosphere.eu)>,
<bound method Mapping.values of <xarray.Dataset>
Data variable pm2p5_conc数据变量 pm2p5_conc
Following dl.meteos's advice I get a Key Error:按照 dl.meteos 的建议,我得到一个关键错误:
def normalize(x):
return 0.5 + (x - x.min()) / (x.max() - x.min())
risk = normalize(pmScatter["pm25"]["pm2p5_conc"].values)* pop.pop_2010[::resolution].values * normalize(covidExtra.hosp[::resolution].values) gives me the following error:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
<ipython-input-14-47c4a255de66> in <module>
----> 1 risk = normalize(pmScatter["pm25"]["pm2p5_conc"].values)* pop.pop_2010[::resolution].values * normalize(covidExtra.hosp[::resolution].values)
2 risk = np.vstack((x,y,risk)).T
3 risk = pd.DataFrame(risk,columns=['lon','lat','risk'])
4
~/.pyenv/versions/lewagon/lib/python3.8/site-packages/pandas/core/series.py in __getitem__(self, key)
851
852 elif key_is_scalar:
--> 853 return self._get_value(key)
854
855 if is_hashable(key):
~/.pyenv/versions/lewagon/lib/python3.8/site-packages/pandas/core/series.py in _get_value(self, label, takeable)
959
960 # Similar to Index.get_value, but we do not fall back to positional
--> 961 loc = self.index.get_loc(label)
962 return self.index._get_values_for_loc(self, loc, label)
963
~/.pyenv/versions/lewagon/lib/python3.8/site-packages/pandas/core/indexes/range.py in get_loc(self, key, method, tolerance)
352 except ValueError as err:
353 raise KeyError(key) from err
--> 354 raise KeyError(key)
355 return super().get_loc(key, method=method, tolerance=tolerance)
356
KeyError: 'pm2p5_conc'
You are access the xarray.Dataset
using values method which yields to a type casting reverting a numpy array.您正在使用 values 方法访问xarray.Dataset
,该方法产生类型转换以恢复 numpy 数组。
The solution is quite easy:解决方案很简单:
pmScatter["pm25"]["pm2p5_conc"].values
Calling .values
on a xarray.DataArray
.在.values
上调用xarray.DataArray
。 Please take a look into the xarray Documentation to learn the difference between DataArray
and Dataset
.请查看 xarray 文档以了解DataArray
和Dataset
之间的区别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.