How do I fillna on a Pandas DataFrame that has a datetime64 dtype? I want the result to be empty string, not a default date.
I thought this would do it. But unfortunately it gives me NaT instead of empty string.
df.date = df.date.fillna('')
Here is full code
import pandas as pd
import numpy as np
np.random.seed(0)
rng = pd.date_range('2015-02-24', periods=5, freq='T')
df = pd.DataFrame({ 'date': rng, 'val': np.random.randn(len(rng)) })
This gives me a dataframe that looks like this
date val
2015-02-24 00:00:00 1.764052
2015-02-24 00:01:00 0.400157
2015-02-24 00:02:00 0.978738
2015-02-24 00:03:00 2.240893
But say one of the dates is nan
df.at[0, 'date'] = np.nan
I get back this dataframe
date val
NaT 1.764052
2015-02-24 00:01:00 0.400157
2015-02-24 00:02:00 0.978738
2015-02-24 00:03:00 2.240893
What I want is this
date val
1.764052
2015-02-24 00:01:00 0.400157
2015-02-24 00:02:00 0.978738
2015-02-24 00:03:00 2.240893
But I don't know how to do it. And this following code unfortunately doesn't work.
df.date = df.date.fillna('')