5

I have a DatetimeIndex object comprised of two dates given as follows:

import pandas as pd
timestamps = pd.DatetimeIndex(['2014-1-1', '2014-1-2'], freq='D')

which looks like this:

DatetimeIndex(['2014-01-01', '2014-01-02'], dtype='datetime64[ns]', freq='D')

How do I get a list of dates from the timestamps object? i.e. I want the following:

['2014-01-01', '2014-01-02']
vvvvv
  • 25,404
  • 19
  • 49
  • 81
ajrlewis
  • 2,968
  • 3
  • 33
  • 67

2 Answers2

6

to_native_types() converts the values of timestamps to str format and then tolist() creates a list of str (dates).

timestamps.to_native_types().tolist()

Output

['2014-01-01', '2014-01-02']
vb_rises
  • 1,847
  • 1
  • 9
  • 14
4

Can you try the following:

timestamps.strftime('%Y-%m-%d').tolist()

Output:

['2014-01-01', '2014-01-02']
Jeril
  • 7,858
  • 3
  • 52
  • 69