首页 > 解决方案 > Ipython 小部件下拉列表,包括 NaN 值

问题描述

我有一个 ipython 小部件下拉列表,其中包括 NaN:

from ipywidgets import widgets
import numpy as np
widgets.Dropdown(description='Choose this:', options=[None, 'a', 'b', np.nan])

当我尝试选择 NaN 时,出现以下错误:

StopIteration                             Traceback (most recent call last)
...

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
...
ValueError: nan not in array

During handling of the above exception, another exception occurred:

TraitError                                Traceback (most recent call last)
...
TraitError: Invalid selection: value not found

我删除了 Tracebacks,因为机器人迫使我添加更多细节,因为我的帖子“主要是代码”。

起初我以为我们只能在下拉列表中使用文字,但使用对象通常可以正常工作。NaN有什么特别之处?

标签: python-3.xnumpyipywidgets

解决方案


推荐阅读