Skip to content
Advertisement

Pandas fillna on datetime object

I’m trying to run fillna on a column of type datetime64[ns]. When I run something like: df['date'].fillna(datetime("2000-01-01"))

I get: TypeError: an integer is required

Any way around this?

Advertisement

Answer

This should work in 0.12 and 0.13 (just released).

@DSM points out that datetimes are constructed like: datetime.datetime(2012,1,1) SO the error is from failing to construct the value the you are passing to fillna. Note that using a Timestamp WILL parse the string.

JavaScript

datetime.datetime will work as well

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement