Python: Convert Object Column Into Datetime And Compare With Current Date
My dataframe has a column containing dates like +-----+---------------------+ | Nr | Date | +-----+---------------------+ | 146 | 2011-03-11 00:00:00 | | 654 | 201
Solution 1:
Pandas uses a timestamp represented in a nanosecond resolution. Since the timestamp is stored in a 64-bit number, the span of the timestamp is limited and should lie between a certain range.
The range is specified here
Solution 2:
If you want to keep only future dates, and you want to keep your dates with years 9999, you could do something like:
df['Date'][(pd.to_datetime(df['Date'], errors = 'coerce') > pd.to_datetime('today')) | (pd.to_datetime(df['Date'], errors = 'coerce').isnull())]
This will work for the data you have shown but will pass True for any NaTs, so be careful.
Solution 3:
This OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 9999-12-31 00:00:00 error is because you are converting string to datetime with year 9999. The timestamp limitations in pandas is only for 584 years (1677-2262)
Post a Comment for "Python: Convert Object Column Into Datetime And Compare With Current Date"