The quarter
attribute returns the quarter of the year for any given Timestamp object (an equivalent of Python's datetime
object).
For a given year, there are four (4
) quarters. The quarter
attribute will return 1
if the given date can be found in the first quarter. It returns 2
if the given date can be found in the second quarter, and so on.
The quarter
attribute takes the following syntax:
Timestamp.quarter
Since it is an attribute, quarter
takes no parameter value.
The quarter
attribute returns an int
from 1
to 4
representing the quarter for which the input date time
object can be found.
# A code to illustrate the quarter attribute in Pandas# importing the pandas libraryimport pandas as pd# creating a date time objectmy_date = pd.Timestamp(2022, 4, 29)# obtaing the quarter of the given yearprint("The given date can be found in quarter ", my_date.quarter)
pandas
library.datetime
object, my_date
.datetime
object using the quarter
attribute.