I have a dataframe with date column where it looks like this. There are more than one date column such as end date, fiscal year date etc.
Plan Start Date
8/16/2017 0:00
5/31/2017 0:00
5/31/2017 0:00
5/31/2017 0:00
5/31/2017 0:00
4/21/2016 0:00
2/25/2016 0:00
12/15/2016 0:00
12/15/2016 0:00
12/15/2016 0:00
42373
42373
42367
42367
42367
42367
42460
42460
42460
42460
42460
42759
42333
I am trying to write a function where it basically changes those integrers to appropriate date format and format this column as datetime[64]. this column format is current object type.
I have written below function
def change_date_df(df):
format_dates_df = [col for col in df.columns if 'Date' in col];
for date in format_dates_df:
df[date] = pd.to_datetime(df[date]).apply(lambda x: x.strftime('%d-%m-%y')if not pd.isnull(x) else '');
return df;
Its giving back now a
ValueError: mixed datetimes and integers in passed array
Im guessing these numbers are not being converted to dates. but Im not sure how else i can adjust my code.
Any idea?
Adam