Python 为什么Bokeh数据表中有Nan值?

Python 为什么Bokeh数据表中有Nan值?,python,jupyter-notebook,bokeh,Python,Jupyter Notebook,Bokeh,我已经编写了两个函数来基于输入Dataframe创建datatable。由于某些原因,值丢失,输出仅显示nan值 from bokeh.models import ColumnDataSource, DataRange1d\ ,Plot, LinearAxis, Grid,Label,LabelSet,HoverTool,NumeralTickFormatter from bokeh.models.glyphs import HBar from bokeh.io import curdoc, s

我已经编写了两个函数来基于输入Dataframe创建datatable。由于某些原因,值丢失,输出仅显示nan值

from bokeh.models import ColumnDataSource, DataRange1d\
,Plot, LinearAxis, Grid,Label,LabelSet,HoverTool,NumeralTickFormatter
from bokeh.models.glyphs import HBar
from bokeh.io import curdoc, show, output_file
from bokeh.models.layouts import Column
from bokeh.resources import INLINE
import bokeh.io
bokeh.io.output_notebook() 
from bokeh.plotting import figure
from bokeh.sampledata.commits import data
from bokeh.transform import jitter
from bokeh.models.widgets import Panel, Tabs
from bokeh.layouts import widgetbox, Column
from bokeh.models.widgets import DataTable, DateFormatter, TableColumn,NumberFormatter,Panel, Tabs

def create_data_source(DF):
    columns = []
    DF = DF.reset_index().set_index('ServicedOn').T
    for item in DF:
        columns.append(TableColumn(field=items,
                                    title=item,
                                    width = 1000,
                                    formatter=NumberFormatter(format='0,0')))
    source = DF.drop('Year').to_dict(orient= 'list')
    return (source,columns)
def Create_data_table(DF,year):
        width = 1000
        source, columns = create_data_source(DF.loc[DF.index == str(year)])
        if 3 > len(source) < 7:
            width = 500
        elif len(source) < 3:
            width = 300
        Data_table = ( DataTable(columns = columns,source=ColumnDataSource(source),
                  height = 100, width = width,row_headers= False) )
        return (Panel(child=Data_table, title=str(year)))
show(Tabs(tabs = [Create_data_table(PD2,2016)]))

我已经阅读了代码,但无法理解值在哪里丢失。有什么想法吗?

您的代码有错误:项目而不是项目

# your code : columns.append(TableColumn(field=items, title=item [...]
columns.append(TableColumn(field=item, title=item [...]

可能是因为:bokeh找不到数据

我在运行代码时有很多错误:items而不是item,DF.loc[DF.index==str(year)]。。。请你能分享一个可运行的代码,这样我就可以测试并找出问题所在吗?哈哈,我想这就是错误(项目)。我一定没有看到。非常感谢louc,请把错误贴出来作为你的答案,这样我就可以投票了!很高兴有用:)是的,就是这样!Bokeh找不到数据,但从未抛出错误。
# your code : columns.append(TableColumn(field=items, title=item [...]
columns.append(TableColumn(field=item, title=item [...]