The following sequence is an excerpt from the pandas DataFrame that I have:
>>> df_t value 2011-01-31 -5.575000 2011-03-31 7.700000 2011-05-31 15.966667 2011-07-31 10.683333 2011-08-31 10.454167 2011-10-31 9.320833 2011-12-31 -0.358333 2012-01-31 -11.550000 2012-03-31 1.700000 2012-05-31 12.333333 2012-07-31 12.816667 2012-08-31 11.837500 2012-10-31 2.733333 2012-12-31 4.075000 2013-01-31 2.450000 2013-03-31 -4.262500 2013-05-31 11.491667 2013-07-31 14.812500 2013-08-31 13.920833 2013-10-31 4.125000 2013-12-31 0.075000
How can I delete March 31st in every leap year? I tried something like:
def isleap(year): return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0) if isleap(df_t.index.year): df_t=df_t[df_t.index.dayofyear!=91]
... but obviously it was too easy in my head. Is it the only solution to cycle through the entire data frame and check at every step, if the year is a leap year and the date is the 91st day of the year or is a simpler solution available?
EDIT: The problem is not how to determine if a year is a leap year, but if so, delete March 31st in the above frame.
source share