Apologies in advance for this, but after two hours of searching and trying I cannot get the right answer here. I have a data frame, populated via pandas io sql.read_frame().
The column that is proving to be too much for me is of dtype int64. The integers is of the format YYYYMMDD. for example 20070530 - 30th of may 2007. I have tried a range of approaches, the most obvious being;
pd.to_datetime(dt['Date']) and pd.to_datetime(str(dt['Date']))
with multiple variations on the functions different parameters.
The result has been, at best, that the date interpreted as being the time. The date is set to 1970-01-01 - outcome as per above example 1970-01-01 00:00:00.020070530
I also tried various .map() functions found in simular posts.
I have noticed that according to np.date_range() can interpret string values of the format YYYYMMDD, but that is the closest I have come to seeing a solution.
If anyone has an answer, I would be very greatful!
EDIT: In view of the answer from Ed Chum, the problem is most likely related to encoding. rep() on a subset of the dataFrame yields:
OrdNo LstInvDt\n0
9 20070620\n1
11 20070830\n2
19 20070719\n3
21 20070719\n4
23 20070719\n5
26 20070911\n7
29 20070918\n8
31 0070816\n9
34 20070925\n10
This is when LstInvDt is dtype int64.
to_datetimeaccepts a format string sopd.to_datetime(str(t), format='%Y%m%d')should work:In [92]: t = 20070530 pd.to_datetime(str(t), format='%Y%m%d') Out[92]: Timestamp('2007-05-30 00:00:00')- EdChumuff-8, but obviously something is happening that I am not aware of. I will have to look at the sql import part again... Thank you for your help @EdChum. You did answer my question, so I will check your answer as accepted. Looks like I will use most of today trying to find out this one... - Rookie