我正在尝试创建一个 Select 小部件驱动的条形图,并且正在努力完成纯粹实现 Select 小部件的第一部分。
我目前有一个使用以下内容生成的公司列表:
tech_firms = list(sorted(tech_valid['Company Name'].unique()))
据我所知,这只是一个列表。当我在 Jupyter 中调试时,我得到看起来像列表输出的内容(带有滚动条)
不工作:
下面的内容不起作用,我收到错误: 期望 List(Either(String, Tuple(Either(Int, String),String))) 或 Dict(String, List(Either(String, Tuple) 的元素(Either(Int,String)(,String)))),得到 Select(description='Tech Firms', options= ....) 以及 tech_firms
内所有名称的列表
#drop down population
select = Select(title="Tech Firms", value="Apple", options=tech_firms)
show(widgetbox(select))
如果我尝试以下方法,它会起作用,但这根本不是一个有效的解决方案,因为我在列表中有很多名字,并且随着数据集的变化和发展,很可能会出现新公司,而其他公司可能会消失。我错过了什么?
工作:
#drop down population
select = Select(title='Tech Firms', value='Apple', options=['Apple', 'Google', 'DeepMind', 'Amazon'])
show(widgetbox(select))
显示 tech_firms
中的一些值按照要求:
(我从异常中提取了它,以便它在抛出过程中按原样显示):
got Select(description='Tech Firms', options=('Apple', 'Amazon', 'DeepMind', 'Google', 'Tesla, Inc.', 'Arlington Corp.', 'YouTube')
最佳答案
我发现的解决方案是我不必要地将数据框列指定为列表。显然,由于某种原因,这不起作用。
我的解决方案是创建一个新的变量,而不使用以下 tech_firms_list = tech_firms['Company Name'].unique()
创建选择下拉列表后,我在通过以下方式处理选项
参数时对列表进行了排序:
select = Select(title="Tech Firms", value="Amazon Inc.", options=sorted(tech_firms_list))
显然,列表转换作为参数引起了一些问题。如果有人确切知道为什么会发生这种情况,请告诉我,我想对这些机制有一个深入的了解。
关于python - 在 Bokeh 中创建选择列表时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50931998/