如何在 Bokeh 中绘制 'pandas.core.series.Series' 中的前 5 个值?
How to plot the top 5 values in 'pandas.core.series.Series' in Bokeh?
第一列包含名称,第二列包含值。
我怎样才能使用散景绘制它。下面是在 matlabplot
中绘制的代码
new_rf = pd.Series(rf.feature_importances_,index=x.columns).sort_values(ascending=False)
new_rf[:5]
x 取变量名,y 取值
p =figure()
p.vbar(
x = new_rf[:5].index, #here will be the feature name
top = new_rf[:5].values, #here will be feature_importance weight
)
这只是给我一个空的情节
您的代码有问题:
- 您创建
new_rf
但使用 imp_feat_rf
。我假设在将代码复制到 SO 时只是部分重命名
vbar()
需要 width
参数。当您 运行 代码 时,您应该会在 Python 输出中看到此错误
- 使用分类数据需要为范围设置明确的类别。更多详细信息,请访问 https://docs.bokeh.org/en/latest/docs/user_guide/categorical.html。请注意
x_range
参数接受列表但不接受 pandas 索引,因此您必须将索引转换为列表
第一列包含名称,第二列包含值。 我怎样才能使用散景绘制它。下面是在 matlabplot
中绘制的代码new_rf = pd.Series(rf.feature_importances_,index=x.columns).sort_values(ascending=False)
new_rf[:5]
x 取变量名,y 取值
p =figure()
p.vbar(
x = new_rf[:5].index, #here will be the feature name
top = new_rf[:5].values, #here will be feature_importance weight
)
这只是给我一个空的情节
您的代码有问题:
- 您创建
new_rf
但使用imp_feat_rf
。我假设在将代码复制到 SO 时只是部分重命名
vbar()
需要width
参数。当您 运行 代码 时,您应该会在 Python 输出中看到此错误
- 使用分类数据需要为范围设置明确的类别。更多详细信息,请访问 https://docs.bokeh.org/en/latest/docs/user_guide/categorical.html。请注意
x_range
参数接受列表但不接受 pandas 索引,因此您必须将索引转换为列表