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)
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',
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With