Consider a pd.Series which contains a date column with integers, e.g. 01052012. What is the best way to convert this?
Example:
tDate
0 20040915
1 20041020
2 20041117
3 20041222
4 20050119
.. ...
203 20210818
204 20210915
205 20211020
206 20211117
207 20211222
Using pd.TimeStamp(x) outputs:
>> pd.Timestamp(x.data.tDate[0])
Timestamp('1970-01-01 00:00:00.020040915')
I can do loop over each element and do the following, but it's most likely not a good practice:
y = x.values[0][0])[:4]
m = x.values[0][0])[4:6]
d = x.values[0][0])[6:]
pd.Timestamp(int(y),int(m),int(d))
20040915should result in2004-09-15?pd.datetime(x.data.tDate, format='%Y%m%d', errors='coerce'), considering tDate is a pandas series column