- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements