1
raw_data = {'Event': ['A','B','C','D', 'E'],
            'dates': ['08-12-1600','26-09-1400', '04-11-1991','25-03-1991', '10-05-1991']}
df_1 = pd.DataFrame(raw_data, columns = ['Event', 'dates'])

df_1['dates'] = pd.to_datetime(df_1['dates'])

the above code gives error due to date 08-12-1600 if the date is removed it works fine, what could be the possible reason for it? error is: Out of bounds nanosecond timestamp: 1600-08-12 00:00:00

  • I think that [this overview of timestamp limitations](http://pandas-docs.github.io/pandas-docs-travis/user_guide/timeseries.html#timestamp-limitations) in the docs might help you – sacuL May 17 '21 at 15:10
  • Answer on your question can be founded [here](https://stackoverflow.com/questions/32888124/pandas-out-of-bounds-nanosecond-timestamp-after-offset-rollforward-plus-adding-a). – okrn May 17 '21 at 15:12
  • Does this answer your question? [pandas out of bounds nanosecond timestamp after offset rollforward plus adding a month offset](https://stackoverflow.com/questions/32888124/pandas-out-of-bounds-nanosecond-timestamp-after-offset-rollforward-plus-adding-a) – MattDMo Mar 25 '23 at 19:51

1 Answers1

2

That is because the provided dates are outside the range of Timestamp.

pd.Timestamp.min
Timestamp('1677-09-21 00:12:43.145225')

pd.Timestamp.max
Timestamp('2262-04-11 23:47:16.854775807')

Details here

If we need the dates even out of range

Then we can convert them to period using below code

raw_data = {'Event': ['A','B','C','D', 'E'],
            'dates': ['08-12-1600','26-09-1400', '04-11-1991','25-03-1991', '10-05-1991']}
df_1 = pd.DataFrame(raw_data, columns = ['Event', 'dates'])


def conv(x):
    day,month,year = tuple(x.split('-'))
    return pd.Period(year=int(year), month=int(month), day=int(day), freq="D")

df_1['dates'] = df_1.dates.apply(conv)
df_1

Output

    Event   dates
0   A   1600-12-08
1   B   1400-09-26
2   C   1991-11-04
3   D   1991-03-25
4   E   1991-05-10

If we can ignore dates outside range

df_1['dates'] = pd.to_datetime(df_1.dates, errors='coerce')
df_1

Output

    Event   dates
0   A       NaT
1   B       NaT
2   C       1991-04-11
3   D       1991-03-25
4   E       1991-10-05

Bonus Fact

Why timestamp can hold values for around 584 years 1677-2262?

Since timestamps provides nano second precision and is stored in 64-bit integer, hence it can store around 584 years with this nano second resolution in 64-bit int space.

Utsav
  • 5,572
  • 2
  • 29
  • 43