0

I'm having trouble loading some Dates from a csv file, the dates are essentially correct, but they seem to flip from YYYY-DD-MM to YYYY-MM-DD, and it would appear it depends on whether the Day with in the Date is below the 10th or not. When I look at the csv in Excel however the dates are all of the same format which weirdly is 01/04/19 (DD/MM/YY) , so completely different from what pandas is loading it as.

Here is how the Date column is coming in:

2019-01-04
2019-08-04
2019-04-15
2019-04-22
2019-04-29
2019-06-05
2019-05-13
2019-05-20
2019-05-27
2019-03-06
2019-10-06
2019-06-17
2019-06-24
2019-01-07
2019-08-07

I've tried parsing the date when loading the csv at the beginning and tried things like df['Date'] = pd.to_datetime(df['Date']) but nothing appears to work. Has anyone seen anything like this before?

top bantz
  • 585
  • 1
  • 12
  • 29
  • similar to https://stackoverflow.com/questions/17465045/can-pandas-automatically-recognize-dates Hope this helps....Thanks :) – abhikumar22 Nov 20 '19 at 17:14

1 Answers1

1

you may use df['Date'] = pd.to_datetime(df['DateS'], format='%Y-%m-%d') as follows

df = pd.DataFrame({
    'DateS' : ['2019-01-04', '2019-08-04']
})
df['Date'] = pd.to_datetime(df['DateS'], format='%Y-%m-%d')
df
Prince Francis
  • 2,995
  • 1
  • 14
  • 22