Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
