如何在' pandas.core.series.Series'中绘制前5个值。在散景?

时间:2018-02-12 11:34:18

标签: python plot graph 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
)

这只是给我一个空图

1 个答案:

答案 0 :(得分:0)

您的代码问题:

  1. 您创建new_rf但使用imp_feat_rf。我认为在将代码复制到SO
  2. 时只是部分重命名
  3. vbar()需要width参数。运行代码时,您应该在Python输出中看到此错误
  4. 使用分类数据需要为范围设置明确的类别。有关详细信息,请访问https://bokeh.pydata.org/en/latest/docs/user_guide/categorical.html。请注意x_range参数接受列表,但它不接受pandas索引,因此您必须将索引转换为列表
相关问题