📜  Python| Pandas Series.dt.is_quarter_end(1)

📅  最后修改于: 2023-12-03 14:46:22.928000             🧑  作者: Mango

Python | Pandas Series.dt.is_quarter_end

The Series.dt.is_quarter_end function is a method provided by the Pandas library in Python, which can be used to check if each element in a Series represents the last day of a financial quarter.

Syntax

Series.dt.is_quarter_end

Parameters

This function does not take any parameters.

Returns

The function returns a boolean Series with True values for elements that represent the last day of a quarter, and False values for others.

Example

import pandas as pd

# Create a series with dates
dates = pd.Series(pd.date_range('2022-01-01', periods=8, freq='M'))

# Check if dates are quarter end
is_quarter_end = dates.dt.is_quarter_end

# Print the result
print(is_quarter_end)

Output:

0    False
1    False
2    True
3    False
4    False
5    True
6    False
7    False
dtype: bool

In the above example, a Series of dates is created using the pd.date_range function, with a frequency of 'M' (monthly). The is_quarter_end function is then applied to the Series to check if each date is a quarter end. The resulting boolean Series is printed, showing True for indexes 2 and 5, which represent the last day of a quarter.

This function is useful in scenarios where it is necessary to identify and analyze data corresponding to the end of financial quarters.