对于以下数据帧(df),
ColA ColA_weights ColB ColB_weights
0 0.038671 1073 1.859599 1
1 20.39974 57362 10.59599 1
2 10.29974 5857 2.859599 1
3 5.040000 1288 33.39599 1
4 1.040000 1064 7.859599 1
Run Code Online (Sandbox Code Playgroud)
我想绘制一个加权箱图,其中每个框的权重分别由ColA_weights和ColB_weights给出,我只是做
df.boxplot(fontsize=12,notch=0,whis=1.5,vert=1,widths=0.2)
Run Code Online (Sandbox Code Playgroud)
但是,似乎没有规定包括权重.有解决方案吗
谢谢!
我有这个人.数据帧:
datetime
2012-01-01 125.5010
2012-01-02 125.5010
2012-01-03 125.5010
2012-02-04 125.5010
2012-02-05 125.5010
2012-02-29 125.5010
2012-02-28 125.5010
2016-01-07 125.5010
2016-01-08 125.5010
2016-02-29 81.6237
Run Code Online (Sandbox Code Playgroud)
我想删除对应于2月29日的所有行,导致foll.数据框:
datetime
2012-01-01 125.5010
2012-01-02 125.5010
2012-01-03 125.5010
2012-02-04 125.5010
2012-02-05 125.5010
2012-02-28 125.5010
2016-01-07 125.5010
2016-01-08 125.5010
Run Code Online (Sandbox Code Playgroud)
现在,我只是手动完成:
df.drop(df.index[['2012-02-29']]).我怎样才能使它适用于所有年份,而不必手动指定行索引.
我正在使用matplotlib制作这个3D图:
ax.plot_surface(x_surf, y_surf, np.reshape(npp, (max_temp/step, max_temp/step)), linewidth=0.2,cmap=palettable.colorbrewer.sequential.Greens_9.mpl_colormap)
Run Code Online (Sandbox Code Playgroud)
有没有办法将具有相同时间维度但不同空间域的2个或更多netCDF文件合并为单个netCDF文件?空间域由纬度和经度坐标指定?在xarray concat,merge等的文档中,他们说它们使用单个维度
如何堆叠以下2个数据帧:
df1
hzdept_r hzdepb_r sandtotal_r
0 0 114 0
1 114 152 92.1
df2
hzdept_r hzdepb_r sandtotal_r
0 0 23 83.5
1 23 152 45
Run Code Online (Sandbox Code Playgroud)
给出以下结果:
hzdept_r hzdepb_r sandtotal_r
0 0 114 0
1 114 152 92.1
2 0 23 83.5
3 23 152 45
Run Code Online (Sandbox Code Playgroud)
使用pandas合并操作不起作用,因为它只是水平排列数据帧(而不是垂直,这是我想要的)
fig, ax = plt.subplots(3, 3, sharex='col', squeeze=False, figsize=(20, 10))
Run Code Online (Sandbox Code Playgroud)
我想绘制7个子图并使用上面的命令.然而,它创建了9个图(包括2个空图).我怎样才能确保只绘制了7个地块?
import xarray as xr
import cartopy.crs as ccrs
USA_PROJ = ccrs.AlbersEqualArea(central_longitude=-97., central_latitude=38.)
g_simple = ds_by_month.t2m.plot(x='longitude',
y='latitude',
col='month',
col_wrap=6,
aspect=ds.dims['longitude'] / ds.dims['latitude'],
subplot_kws=dict(projection=USA_PROJ),
add_colorbar=False,
transform=ccrs.PlateCarree())
g_simple.add_colorbar(orientation='horizontal')
for ax in g_simple.axes.ravel():
ax.coastlines()
ax.set_extent([-121, -72, 22.5, 50])
plt.tight_layout()
plt.show()
Run Code Online (Sandbox Code Playgroud)
如何确保颜色条与图形重叠?即使我使用xarray默认颜色条,也会发生重叠.
我想merf在集成模型中使用(混合效应随机森林)库,例如通过使用mlens或mlxtendpython 库。然而,由于拟合和预测方法的merf结构采用非传统方式,我无法弄清楚如何做到这一点:
from merf import MERF
merf = MERF()
merf.fit(X_train, Z_train, clusters_train, y_train)
y_hat = merf.predict(X_test, Z_test, clusters_test)
Run Code Online (Sandbox Code Playgroud)
有没有办法merf在集成模型中使用该库?问题在于,使用mlens或其他集成库构建集成模型会假定 scikit-learn 结构,其中 fit 方法将X,y作为输入,预测方法将 ,X作为输入。然而,merf显然在拟合和预测方法中都有更多的输入。这是一个简化的语法mlens:
from mlens.ensemble import SuperLearner
ensemble = SuperLearner()
ensemble.add(estimators)
ensemble.add_meta(meta_estimator)
ensemble.fit(X, y).predict(X)
Run Code Online (Sandbox Code Playgroud)
我不限于使用mlens或mlxten。任何其他构建集成模型的方法merf也可以。
我有一个netCDF文件,其时间维度包含2小时的数据.我希望平均每小时获得每小时的平均时数.我试过这个:
import xarray as xr
ds = xr.open_mfdataset('ecmwf_usa_2015.nc')
ds.groupby(['time.month', 'time.hour']).mean('time')
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
*** TypeError: `group` must be an xarray.DataArray or the name of an xarray variable or dimension
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?如果我这样做:
ds.groupby('time.month', 'time.hour').mean('time')
Run Code Online (Sandbox Code Playgroud)
我没有得到错误,但结果的时间维度为12(每个月一个值),而我想要每个月的小时平均值,即每12个月24个值.数据可在此处获取:https://www.dropbox.com/s/yqgg80wn8bjdksy/ecmwf_usa_2015.nc?dl = 0
from os import environb as environ
Run Code Online (Sandbox Code Playgroud)
在Windows Anaconda python 3.6安装中键入以上命令时,我收到此错误:
ImportError: cannot import name 'environb'.
这似乎是因为,
environb is only available if supports_bytes_environ is True.
和
supports_bytes_environ 在Windows上为False.
有办法解决这个问题吗?
参考:https://docs.python.org/3/library/os.html#os.environb
具体来说,我在GRASS GIS Python脚本库中发现了这个错误.