How to create a list of date string in 'yyyymmdd' format with Python Pandas?
Or using list comprehension:
[d.strftime('%Y%m%d') for d in pandas.date_range('20130226','20130302')]
Using format
:
>>> r = pandas.date_range('20130226','20130302')
>>> r.format(formatter=lambda x: x.strftime('%Y%m%d'))
['20130226', '20130227', '20130228', '20130301', '20130302']
or using map
:
>>> r.map(lambda x: x.strftime('%Y%m%d'))
array(['20130226', '20130227', '20130228', '20130301', '20130302'], dtype=object)
Easy and clean: do it directly with pandas date_range and strftime like this:
pd.date_range(start='20130226',end='20130302',freq='D').strftime('%Y%m%d')
Resulting:
Index(['20130226', '20130227', '20130228', '20130301', '20130302'], dtype='object')