My dataframe looks like this: Dataframe
I am trying to select the values between two months. I have already calculated a while loop which selects the start of the month and the end of the month
start_date = date(2014, 1, 1)
end_date = date(2019, 12, 1)
while start_date <= end_date:
end_of_month = start_date + relativedelta(months=1, days=-1)
print (start_date.strftime("%Y-%m-%d"))
print (end_of_month.strftime("%Y-%m-%d"))
start_date = start_date + relativedelta(months=+1)
I always got an error message and so i wanted to try if i can select dates without the loop:
start_date = date(2014, 1, 1)
end_date = date(2019, 12, 1)
Portfolio.loc[start_date:end_date]
I always get the error message KeyError: datetime.date(2014, 1, 1)
, but i don't know why?
Even if i only wanter to filter a single Date: Portfolio.loc[start_date]