Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

pandas
communitycreator

What is the Period.dayofweek() attribute in pandas?

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The dayofweek() attribute in pandas is used to obtain the day of the week the given Period lies in. Monday is given as 0, Tuesday is given as 1, Wednesday is given as 2, and so on and so forth.

Syntax

Period.dayofweek
Syntax for the dayofweek attribute in Pandas

Parameters

The dayofweek, being an attribute, takes no parameter value.

Return value

The dayofweek attribute returns an integer representing the day of week from the given Period object.

Example

# A code to illustrate the dayofweek attribute
# importing the pandas library
import pandas as pd
# creating a Period object
a = pd.Period('2022-5-2 8:00', 'H')
# printing the day of the week
print(a.dayofweek)
Implementing the daysofweek attribute

Explanation

  • Line 3: We import the pandas library.
  • Line 6: We create a Period object, a.
  • Line 9: We obtain the day of the week from the input, Period object, using the dayofweek attribute. We print the value to the console.

RELATED TAGS

pandas
communitycreator

CONTRIBUTOR

Onyejiaku Theophilus Chidalu

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring