Pandas date_range from DatetimeIndex to Date format

For me the current answer is not satisfactory because internally it is still stored as a timestamp with hours, minutes, seconds.

Pandas version : 0.22.0

My solution has been to convert it to datetime.date:

In[30]: import pandas as pd
In[31]: rng = pd.date_range('1/1/2013','1/31/2013', freq='D')
In[32]: date_rng = rng.date   # Here it becomes date
In[33]: date_rng[0]
Out[33]: datetime.date(2013, 1, 1)
In[34]: print(date_rng[0])
2013-01-01

to_pydatetime returns a NumPy array of Python datetime.datetime objects:

In [8]: dates = rng.to_pydatetime()

In [9]: print(dates[0])
2013-01-01 00:00:00

In [10]: print(dates[0].strftime('%Y-%m-%d'))
2013-01-01

Tags:

Python

Pandas