There is a data-frame of sales, with the index being of type: date-time.
rng = pd.date_range('2015-01-03', periods=500)
df = pd.DataFrame({'historical_sales': np.random.choice([100,200,300],
size=500)}, index=rng)
print (df)
We also have a list of special dates, some_dates:
some_dates = ['3/15/2017, '6/14/2017'.....]
Trying to subset data-frame by some_dates:
print(df.loc[some_dates])
I get a Key Error that "None of [[dates]] are in the [index]. Is this because I am sub-setting a list of strings instead of datetime?
As a workaround, to subset the data-frame, this worked:
container = []
for i in some_dates:
container.append(df.loc[i])
dfNew = pd.DataFrame(container)
But i would like to further understand the reason of the error and if the workaround is not a 'bad convention'.