问题
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