如何绘制“中的前5个值”Pandas.core.series波基的系列?

2024-04-19 15:08:37 发布

您现在位置:Python中文网/ 问答频道 /正文

第一列包含名称,第二列包含值。 我怎么能用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
)

这只是给了我一个空洞的情节


Tags: 代码名称newindexherebokeh绘制be
1条回答
网友
1楼 · 发布于 2024-04-19 15:08:37

代码问题:

  1. 创建new_rf,但使用imp_feat_rf。我想这只是部分重命名时复制代码到所以
  2. vbar()需要width参数。当您运行代码时,应该在Python输出中看到这个错误
  3. 使用分类数据需要为范围设置显式类别。更多详细信息请访问https://docs.bokeh.org/en/latest/docs/user_guide/categorical.html。请注意,x_range参数接受列表,但不接受索引,因此必须将索引转换为列表

相关问题 更多 >