0
Start_Time
2016-02-08 05:46:00
2016-02-08 06:07:59
2016-02-08 06:49:27
2016-02-08 07:23:34

This is a column of a dataframe I am working with. How can I add to the dataframe an extra column that holds the day of the week that the Start_Time occurred in each line?

1 Answer 1

1

assuming your column is already a datetime we can use the dt. accessor to use datetime methods

if not use pd.to_datetime(df['Start_Time'])

df['day_name'] = df['Start_Time'].dt.day_name()

or

df['dayofweek'] = df['Start_Time'].dt.dayofweek

           Start_Time day_name  dayofweek
0 2016-02-08 05:46:00   Monday          0
1 2016-02-08 06:07:59   Monday          0
2 2016-02-08 06:49:27   Monday          0
3 2016-02-08 07:23:34   Monday          0
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.