本文介绍了如何在散景表中删除NaN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用bokeh小部件表显示数据,我使用Dateformatter格式化日期,但散景表中的空日期显示'NaN/NaN/NaN',如何删除这些NaN?
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)
当前结果显示:
如何用空字符串替换那些"NaN/NaN/NaN"?
How to replace those "NaN/NaN/NaN" with empty string?
推荐答案
您是否尝试过DataFrame的"fillna"功能?
Have you tried "fillna" function of DataFrame?
以下是示例:
df["record_insert_datetime"].fillna("0/0/0", inplace = True)
这篇关于如何在散景表中删除NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!