Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change date_range into string with the method in array?

import pandas as pd
rng=pd.date_range("20150105","20150620",freq="D",tz="Asia/Hong_Kong")
x=[pd.to_datetime(day).strftime(%Y%m%d) for day in rng]

Now x is a list of date time string, How to change date_range into string with the method in array such as the following method ,not to do with list comprehension ,to do with some method in array?

a = numpy.arange(10)
a.astype(str)
like image 387
showkey Avatar asked Aug 11 '26 06:08

showkey


1 Answers

Here you go:

>>> rng = pd.date_range("20150105","20150620",freq="D",tz="Asia/Hong_Kong")
>>> rng.format(formatter=lambda x: x.strftime('%Y%m%d'))
['20150105',
 '20150106',
 '20150107',
 '20150108',
 ...
like image 88
elyase Avatar answered Aug 12 '26 20:08

elyase



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!