Pandas provide us with the day attribute that allows extracting the day from a given timestamp object.
To use this attribute, you need to construct a Timestamp object. You can do this using the timestamp() function as shown:
# import pandas
import pandas as pd
ts = pd.Timestamp('2022-04-04')
The above example creates a Pandas timestamp object from a datetime-time string. The resulting output is as shown:
You can explore the Pandas timestamp() function in the resource shown:
Extract Day From Timestamp Object
To extract the day from the timestamp object shown above, we can run the code as shown:
The above should return the day from the provided timestamp object.
Get Day of Week
You can also fetch the day name from a timestamp object using the day_name() function.
An example is as shown:
This was a short tutorial depicting how to extract the day and day name from a timestamp object.