Date Functionality
In today's lecture, we explored time series and date functionality in pandas. Manipulating dates and times in pandas is highly flexible, enabling us to conduct advanced analysis such as time series analysis.
Timestamp
Pandas has four main time-related classes: Timestamp, DatetimeIndex, Period, and PeriodIndex.
Creating Timestamps
A Timestamp represents a single point in time. It can be created using a string or by passing multiple parameters.
# Creating a Timestamp from a string
pd.Timestamp('9/1/2019 10:05AM')
# Creating a Timestamp by passing multiple parameters
pd.Timestamp(2019, 12, 20, 0, 0)
Timestamp Attributes
Timestamps have several useful attributes.
# Getting the weekday of a Timestamp (1=Monday, 7=Sunday)
pd.Timestamp(2019, 12, 20, 0, 0).isoweekday()
# Extracting the second from a Timestamp
pd.Timestamp(2019, 12, 20, 5, 2, 23).second