-1

I have a pandas dataframe with one column called "date" with dates from 10/1/2018 to 5/1/2020 and one column called "sales" with total sales of the day. I set "date" as index and I want to have another column to show the day of the dates (e.g. Monday, Tuesday, Wednesday...). Is there any dataframe function to do that?

Thank you.

0

3 Answers 3

1

assuming your 'date' column is in proper datetime format (use pd.to_datetime() if not:

df['day_of_week'] = df['date'].dt.day_name() 
Sign up to request clarification or add additional context in comments.

Comments

0

You can use dt.day_name as answered here.

Briefly, it works like....

df['day_of_the_week'] = df['date'].dt.day_name() 

Comments

0

You can use calendar.weekday:

Returns the day of the week (0 is Monday) for year (1970–…), month (1–12), day (1–31).

Or datetime.weekday:

Return the day of the week as an integer, where Monday is 0 and Sunday is 6. The same as self.date().weekday(). See also isoweekday().

For dataframe, take a look at https://stackoverflow.com/a/55648922/1513933

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.