0

How can I tell pandas to return datetime64 rather than Timestamp? For example, in the following code df['dates'][0] returns a pandas Timestamp object rather than the numpy datetime64 object that I put in.

Yes, I can convert it after getting it, but is it possible to tell pandas to give me back exactly what I put in?

>>> import numpy as np
>>> import pandas as pd
>>> np.__version__
'1.10.4'
>>> pd.__version__
u'0.19.2'
>>> df = pd.DataFrame()
>>> df['dates'] = [np.datetime64('2019-02-15'), np.datetime64('2019-08-15')]
>>> df.dtypes
dates    datetime64[ns]
dtype: object
>>> type(df['dates'][0])
<class 'pandas.tslib.Timestamp'>
Steve Schulist
  • 931
  • 1
  • 11
  • 18

1 Answers1

0

Adding values

df.dates.values[0]
Out[55]: numpy.datetime64('2019-02-15T00:00:00.000000000')

type(df.dates.values[0])
Out[56]: numpy.datetime64
BENY
  • 317,841
  • 20
  • 164
  • 234