Skip to content Skip to sidebar Skip to footer

Most Efficient Way To Remove Particular Dates (29 Feb) From Time Series

I have a pandas DF with c. 160k dated observations over 10 years, and want to remove all those from 29 Feb in leap years to enable consistent day on day comparisons across all year

Solution 1:

df['leapday'] = temp_data['Date'].dt.month.eq(2) & temp_data['Date'].dt.day.eq(29)

to drop Feb. 29:

temp_data = temp_data.loc[~(temp_data['Date'].dt.month.eq(2) & temp_data['Date'].dt.day.eq(29))] 

there is also an attribute to check for a leap year:

DateTimeSeries.dt.is_leap_year

Post a Comment for "Most Efficient Way To Remove Particular Dates (29 Feb) From Time Series"