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

why are there Nan values in Bokeh Datatable?

我编写了几个函数来创建基于输入 Dataframe 的数据表。由于某种原因,值丢失并且输出仅显示 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)]))

样本数据框是这样的:

    ServicedOn  amount_spent
Year        
2016    October 31302
2016    November    5750
2016    December    0

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

您的代码有错误:itemS 而不是 item

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

可能是因为bokeh找不到数据