Python - Convert Date String From Yyyy-mm-dd To Dd-mmm-yyyy Using Datetime?
So I have read a number of threads on this, and am still stumped. Any help would be sincerely appreciated. I have a column in a dataframe that contains strings of dates, or nothing
Solution 1:
You probably just need to assign the result back to the column itself:
df_combined['VisitDate'] = df_combined['VisitDate'].apply(lambda x: datetime.datetime.strptime(x, '%Y-%m-%d').strftime('%d-%b-%Y') if x != ""else"")
Solution 2:
No need apply
by using pd.to_datetime
pd.to_datetime(df_combined['VisitDate'],errors='coerce',format='%d-%b-%Y').fillna('')
Post a Comment for "Python - Convert Date String From Yyyy-mm-dd To Dd-mmm-yyyy Using Datetime?"