Reputation: 43
I have a pandas dataframe that has a datetime column called "time". From this column, I only want to extract the year-month-date in the syntax it is given in, and I want to create a new column with that value as a string. Please help!
Upvotes: 1
Views: 3114
Reputation: 4761
IIUC pandas.Series.dt.strftime
is what you want:
df["new_time"] = df["time"].dt.strftime("%Y-%m-%d")
Also, check this documentation where you can find the datetime format codes.
Upvotes: 1