使用数据框在 Bokeh 中构建 Select 小部件

Build Select widget in Bokeh using data frames

我有一个数据框 df,列为 "location"(几个没有值的单元格)-

location
US
India

US
Japan
US

India

我想使用散景创建一个单选小部件,其值包含在位置列中。我正在写下面的代码 -

location = Select(title="Location", value="All",
           options=df["location"].unique())

这给了我一个错误 -

ValueError: expected an element of List(Either(String, Tuple(String, 
String))), got array(['US', 'India', 'EMEA', nan, 'Japan'], 
dtype=object)

您需要将 pandas 系列转换为列表。

options=df["location"].unique().tolist()