I have datasets which have the dates in the format of yyyymmdd. For example, May 5th, 2018 would be 20180505.
How can I reformat these entries such that they will be a time series in pandas?
I have datasets which have the dates in the format of yyyymmdd. For example, May 5th, 2018 would be 20180505.
How can I reformat these entries such that they will be a time series in pandas?
Try this:
from datetime import datetime
a = '20180505'
date = datetime.strptime(a, '%Y%m%d').strftime('%m/%d/%Y')
From this link: Convert integer (YYYYMMDD) to date format (mm/dd/yyyy) in python
You may want also to change the format and this is an example:
df = pd.DataFrame({'dates': ['20180505','20180506','20180507','20180508']})
print df
dates
0 20180505
1 20180506
2 20180507
3 20180508
df['dates'] = pd.to_datetime(df['dates'], format='%Y%m%d').dt.strftime('%d/%b/%Y')
print df
Output:
dates
0 05/May/2018
1 06/May/2018
2 07/May/2018
3 08/May/2018