You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importpandasaspdimportpandasaspdimportnumpyasnp# Create a sample DataFrame with a datetime columndata= {'Datetime': pd.to_datetime(['2022-01-01', '2022-01-02', '2022-01-03', '2022-01-04'])}
df=pd.DataFrame(data)
# Assign NaN values to specific rows or cellsdf.loc[1, 'Datetime'] =np.nandf.loc[3, 'Datetime'] =np.nanprint(df)
print(df.dtypes)
importpanelaspnpn.extension("perspective")
pn.pane.Perspective(df, sizing_mode="stretch_width").servable()
format_cell.js:71 Uncaught (in promise) RangeError: Invalid time value
Hacky Workaround
Replace the NaT value with a valid timestamp
importpandasaspdimportpandasaspdimportnumpyasnp# Create a sample DataFrame with a datetime columndata= {'Datetime': pd.to_datetime(['2022-01-01', '2022-01-02', '2022-01-03', '2022-01-04'])}
df=pd.DataFrame(data)
# Assign NaN values to specific rows or cellsdf.loc[1, 'Datetime'] =np.NANdf.loc[3, 'Datetime'] =np.NANprint(df)
print(df.dtypes)
NAT_TIMESTAMP=pd.Timestamp('1980-01-01')
def_clean_for_perspective(data: pd.DataFrame):
datetime_columns=data.select_dtypes(include='datetime64[ns]').columnsdata[datetime_columns] =data[datetime_columns].fillna(NAT_TIMESTAMP)
returndatadf=_clean_for_perspective(df)
importpanelaspnpn.extension("perspective")
pn.pane.Perspective(df, sizing_mode="stretch_width").servable()
The text was updated successfully, but these errors were encountered:
MarcSkovMadsen
changed the title
Perspective does not show data if datetime column contains NaN
Perspective does not show data if datetime column contains NaT
Jan 5, 2024
I'm on Panel==1.3.6 trying to use Perspective.
format_cell.js:71 Uncaught (in promise) RangeError: Invalid time value
Hacky Workaround
Replace the
NaT
value with a valid timestampThe text was updated successfully, but these errors were encountered: