I need a function to count the total number of days in the 'days' column between a start date of 1st Jan 1995 and an end date of 31st Dec 2019 in a dataframe taking Leapyears into account as well
For example:
- 1st Jan 1995 - Day 1
- 1st Feb 1995 - Day 32
- 2nd Feb 1995 - Day 33...
And so on all the way to 31st Dec 2019.
This is the function I created initially but it doesn't work.
prices
is the name of the data frame and 'days'
is the column where the number of days is to reflect.
def date_difference(self):
for i in range(prices.shape[0] - 1):
prices['days'][i+1] = (prices['days'][i+1] - prices['days'][i])