Remove leap year day from pandas dataframe
You can mask it and remove boolean indexing
:
df = df[(df.index.month != 2) | (df.index.day != 29)]
Solution with function:
def is_leap_and_29Feb(s):
return (s.index.month != 2) | (s.index.day != 29)
mask = is_leap_and_29Feb(df)
print mask
#[False False False False False True False False False True]
print df.loc[~mask]
# datetime
#2012-01-01 125.501
#2012-01-02 125.501
#2012-01-03 125.501
#2012-02-04 125.501
#2012-02-05 125.501
#2012-02-28 125.501
#2016-01-07 125.501
#2016-01-08 125.501
Or:
(s.index.month != 2) | (s.index.day != 29)
If your dataframe has already the datetime
column as index you can:
df = df[~((df.index.month == 2) & (df.index.day == 29))]
this should remove the rows containing the day February 29th for all years.