How to remove NaN in bokeh table

寵の児 提交于 2020-01-25 08:22:08

问题


I am using bokeh widgets table to show data, I use Dateformatter to format date, but null date is showing 'NaN/NaN/NaN' in Bokeh table, how to remove these NaN?

import numpy as np
from bokeh.io import output_notebook
output_notebook()

c, conn = connection()

sqlString = "SELECT * FROM Database.SQLTable;"
df = pd.read_sql_query(sqlString, conn)
c.close()
conn.close()

#df = df.replace(np.nan, '', regex=True)

cols = [
    TableColumn(field='ID', title='ID'),
    TableColumn(field='Activity_Title', title='Activity_Title'), 
    TableColumn(field='Originator', title='Originator'), 
    TableColumn(field='Country', title='Country'), 
    TableColumn(field='Activity_Date', title='Activity_Date', formatter=DateFormatter(format="%m/%d/%Y")), 
    TableColumn(field='record_insert_datetime', title='record_insert_datetime', formatter=DateFormatter(format="%m/%d/%Y"))
]     

data_table = DataTable(columns=cols, source=ColumnDataSource(df), fit_columns=True)

current result is showing:

How to replace those "NaN/NaN/NaN" with empty string?


回答1:


Have you tried "fillna" function of DataFrame?

Here is example:

df["record_insert_datetime"].fillna("0/0/0", inplace = True)


来源:https://stackoverflow.com/questions/58654241/how-to-remove-nan-in-bokeh-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!