按照标题,在显示带有一些空单元格并结合格式化程序的表时遇到了麻烦。
考虑以下示例,该示例改编自官方documentation(使用Bokeh的最新版本,0.13.0)。
from datetime import date
from random import randint
from bokeh.io import output_file, show
from bokeh.layouts import widgetbox
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import \
DataTable, DateFormatter, TableColumn, NumberFormatter
output_file("data_table.html")
n = 1000
data = dict(
dates=[
date(randint(1970, 2018), randint(1, 12), randint(1, 28))
for i in range(n)],
downloads=[randint(0, 100) for i in range(n)],
latency=[randint(0, 100) for i in range(n)],
)
data['dates'][0:5] = [None] * 5
data['downloads'][0:10] = [None] * 10
data['latency'][5:10] = [None] * 5
source = ColumnDataSource(data)
columns = [
TableColumn(
field="dates", title="Date",
formatter=DateFormatter()),
TableColumn(
field="downloads", title="Downloads",
formatter=NumberFormatter()),
TableColumn(
field="latency", title="Latency")
]
data_table = DataTable(source=source, columns=columns, width=800, height=400)
show(widgetbox(data_table))
下表中的结果:
关键方面是:
DateFormatter()
格式化,None
单元格不是空的,而是显示function(){ return c.convert(arguments)}
。NumberFormatter()
设置格式,None
单元格不是空的,但显示出更容易接受的0
。所以,我的问题是:
None
的单元格都为空(同时保持正确的格式)?