TypeError: '>=' not supported between instances of 'datetime.date' and 'str'

The thing is you want to slice using Strings '2017-07-07' while your index is of type datetime.date. Your slices should be of this type too.

You can do this by defining your startdate and endate as follows:

import pandas as pd

startdate = pd.to_datetime("2017-7-7").date()
enddate = pd.to_datetime("2017-7-10").date()
df.loc[startdate:enddate]

startdate & enddate are now of type datetime.date and your slice will work .

The thing is you want to slice using Strings '2017-07-07' while your index is of type datetime.date. Your slices should be of this type too.

You can do this by defining your startdate and endate as follows FaceTime PC:

import pandas as pd

startdate = pd.to_datetime("2017-7-7").date()
enddate = pd.to_datetime("2017-7-10").date()
df.loc[startdate:enddate]