The following piece of code:
import pandas as pd
import numpy as np
data = pd.DataFrame({'date': ('13/02/2012', '14/02/2012')})
data['date'] = data['date'].astype('datetime64')
works fine on one machine (windows) and doesn't work on another (linux). Both numpy and pandas are installed on both.
The error I get is:
ValueError: Cannot create a NumPy datetime other than NaT with generic units
What does this error mean? I see it for the first time ever and there is not much on the web I can find. Is it some missing dependency?
Starting in NumPy 1.7, there are core array data types which natively support datetime functionality. The data type is called datetime64 , so named because datetime is already taken by the Python standard library.
Do this instead. Pandas keeps datestimes internally as datetime64[ns]
. Conversions
like this are very buggy (because of issues in various numpy version, 1.6.2 especially). Use
the pandas routines, then operate like thesee are actual datetime objects. What are you trying to do?
In [30]: pandas.to_datetime(data['date'])
Out[30]:
0 2012-02-13 00:00:00
1 2012-02-14 00:00:00
Name: date, dtype: datetime64[ns]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With