Reputation: 383
I'm trying to convert my column type from object to date. But, I got an error that says
OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 20-04-09 00:00:00
After looking at the data and trying to find the error, I saw the all the dates that I have has the following format:
print(df['date'])
0 020-04-02
1 020-04-02
2 020-04-05
3 NaN
4 020-04-05
...
60 NaN
61 020-04-07
62 NaN
63 020-04-09
64 020-04-09
As you can see the dates begin with a zero, so adding a 2 at the beginning will fix the problem for me. So, the question is, how can I add a 2 while ignoring the NaNs?
Upvotes: 1
Views: 68
Reputation: 863501
If add 2
to missing values there are still missing values, so use:
pd.to_datetime('2' + df['date'])
Upvotes: 1