
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python - Get the weekday from Timestamp object in Pandas
To get the weekday from Timestamp object, use the timestamp.weekday() method. At first, import the required libraries −
import pandas as pd import datetime
Set the timestamp in Pandas. Create a Timestamp object
timestamp = pd.Timestamp(datetime.datetime(2021, 5, 12))
Get the weekday of the year. Weekday is represented by number Monday == 0, Tuesday == 1 … Sunday == 6
timestamp.weekday()
Example
Following is the code
import pandas as pd import datetime # set the timestamp in Pandas # create a Timestamp object timestamp = pd.Timestamp(datetime.datetime(2021, 5, 12)) # display the Timestamp print("Timestamp...\n", timestamp) # getting the weekday of the year res = timestamp.weekday() # display only the weekday # weekday represented by number Monday == 0, Tuesday == 1 … Sunday == 6 print("\nGet the weekday from Timestamp...\n", res)
Output
This will produce the following code
Timestamp... 2021-05-12 00:00:00 Get the weekday from Timestamp... 2
- Related Articles
- Python Pandas - Get the current date and time from Timestamp object
- Python Pandas - Convert PeriodIndex object to Timestamp
- Python Pandas - Get the year from the Period object
- Python Pandas - Get the year from the PeriodIndex object
- Python Pandas - Return the Timestamp representation of the Period object
- Pandas - Convert a Timestamp object to a native Python datetime object
- Python Pandas - Get the Day of the year from Period object
- Python Pandas - Get the quarter of the year from Period object
- Python Pandas - Convert PeriodIndex object to Timestamp and set the frequency
- Python Pandas - Get the Total seconds in the duration from the Timedelta object
- Comparing Timestamp in Python – Pandas
- Python Pandas - Get the seconds from Timedelta object using integer input
- Python Pandas - Get the seconds from Timedelta object using string input
- Python Pandas - Get the hour of the period from the PeriodIndex object
- Python Pandas - Get the minute of the period from the PeriodIndex object

Advertisements