1

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!

3

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.