Reputation: 3
I have one column given as type object and want to convert it to a datetime:
DataFrame: df
Column: date
Value Format: 1880-01-01T00:00:00.000
Dtype: object
When doing:
df['date'] = pd.to_datetime(dt['date'])
I got the error: Out of bounds nanosecond timestamp: 1583-01-01 00:00:00
Even specifiyng the format:
df['date'] = pd.to_datetime(df['date'], format = '%Y-%m-%dT%H:%M:%S.%f')
I got the same error, any idea why that error occurs and how to solve it?
Upvotes: 0
Views: 181
Reputation: 92
With 1880-01-01T00:00:00.000
, it should work.
But from your error message, it seems that your value is 1583-01-01T00:00:00.000
and it is out of pandas timestamps representation range.
In nanosecond resolution, the timespan that can be represented using a 64-bit integer is limited to approximately 584 years, which is:
print(pd.Timestamp.min)
Output: 1677-09-21 00:12:43.145225
print(pd.Timestamp.max)
Output: 2262-04-11 23:47:16.854775807
But if your value is 1880-01-01T00:00:00.000
, after specifying the format:df['date'] = pd.to_datetime(df['date'])
,
when I print df['date']
, I get:
1880-01-01 00:00:00
Name: date, dtype: datetime64[ns]
Upvotes: 1