FINDSTRING([Report Title],"Norwich",1) > 0 ? "Norwich" : (
FINDSTRING([Report Title],"Ipswich",1) > 0 ? "Ipswich" : (
FINDSTRING([Report Title],"Cambridge",1) > 0 ? "Cambridge" : "NA"))
我目前通过以下方式应用函数
:import pandas as pd
import numpy as np
import xarray as xr
time = pd.date_range('2010-01-01','2018-12-31',freq='M')
lat = np.linspace(-5.175003, -4.7250023, 10)
lon = np.linspace(33.524994, 33.97499, 10)
precip = np.random.normal(0, 1, size=(len(time), len(lat), len(lon)))
ds = xr.Dataset(
{'precip': (['time', 'lat', 'lon'], precip)},
coords={
'lon': lon,
'lat': lat,
'time': time,
}
)
Out[]:
<xarray.Dataset>
Dimensions: (lat: 10, lon: 10, time: 108)
Coordinates:
* lon (lon) float64 33.52 33.57 33.62 33.67 ... 33.82 33.87 33.92 33.97
* lat (lat) float64 -5.175 -5.125 -5.075 -5.025 ... -4.825 -4.775 -4.725
* time (time) datetime64[ns] 2010-01-31 2010-02-28 ... 2018-12-31
Data variables:
precip (time, lat, lon) float64 -0.7862 -0.28 1.236 ... 0.6622 -0.7682
列表重新组合为DataArray
该功能可能与气候有所不同,但此处是归一化等级。
-获取变量值与数据集中该Dataset
的所有其他值相比的排名
-将其设置在month
0-100
有没有一种聪明/更有效的方法,而无需循环和选择?
答案 0 :(得分:1)
感谢这个很好的例子。确实有一种使用groupby
and apply
的简单方法:
def rank_norm(ds, dim):
return (ds.rank(dim=dim) - 1) / (ds.sizes[dim] - 1.0) * 100.0
result = ds.groupby('time.month').apply(rank_norm, args=('time',))