A Timestamp object in pandas is an equivalent of Python's datetime
object. It is a combination of date and time fields.
To combine date and time into a Timestamp object, we use the Timestamp.combine()
function in pandas
.
The syntax to combine date and time into a timestamp is:
Timestamp.combine(date, time)
The Timestamp.combine()
function takes the following parameter values:
date
: This is a datetime.date
object representing the date field.time
: This is a datetime.time
object representing the time field.The Timestamp.combine()
function returns a Timestamp object formed from the combination of the date
and time
object.
Let's look at the code below:
# A code to illustrate the Timestamp.combine() function in Pandas# impoting the pandas libraryimport pandas as pd# importing the date and time modulefrom datetime import date, time# creating a Timestamp object from the date and time combinationmy_datetime = pd.Timestamp.combine(date(2022, 4, 29), time(8,54,15))print(my_datetime)
pandas
library.date
and time
modules.Timestamp.combine()
function by combining the date
and time
. Thereby, we form a datetime
object. We assign the value to a variable, my_datetime
.my_datetime
.