I have a dataframe with a column called date, formatted as string and it looks like this:
date
20200109
20200304
20210112
Is there a way I can format that into datetime?
I have a dataframe with a column called date, formatted as string and it looks like this:
date
20200109
20200304
20210112
Is there a way I can format that into datetime?
You can use pd.to_datetime with custom format=:
df["date"] = pd.to_datetime(df["date"], format="%Y%d%m")  # use "%Y%m%d" if month is first
print(df)
Prints:
        date
0 2020-09-01
1 2020-04-03
2 2021-12-01