w3resource

Pandas Series property: dt.is_year_end

Series.dt.is_year_end property

The is_year_end property is used to check whether a given date is the last day of the year or not.

Syntax:

Series.dt.is_year_end
Pandas Series: dt.is_year_end property

Returns: Series or DatetimeIndex
The same type as the original data with boolean values. Series will have the same name and index. DatetimeIndex will have the same name.

Example:

Python-Pandas Code:

import numpy as np
import pandas as pd
dates = pd.Series(pd.date_range("2019-12-30", periods=3))
dates

Output:

0   2019-12-30
1   2019-12-31
2   2020-01-01
dtype: datetime64[ns]

Python-Pandas Code:

import numpy as np
import pandas as pd
dates = pd.Series(pd.date_range("2019-12-30", periods=3))
dates.dt.is_year_end

Output:

0    False
1     True
2    False
dtype: bool

Python-Pandas Code:

import numpy as np
import pandas as pd
idx = pd.date_range("2019-12-30", periods=3)
idx

Output:

DatetimeIndex(['2019-12-30', '2019-12-31', '2020-01-01'], dtype='datetime64[ns]', freq='D')

Python-Pandas Code:

import numpy as np
import pandas as pd
idx = pd.date_range("2019-12-30", periods=3)
idx.is_year_end

Output:

array([False,  True, False])
Pandas Series: dt.is_year_end property

Previous: Series.dt.is_year_start property
Next: Series.dt.is_leap_year property



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/pandas/series/series-dt-is_year_end.php