I have the following code,
df = pd.read_csv(CsvFileName)p = df.pivot_table(index=['Hour'], columns='DOW', values='Changes', aggfunc=np.mean).round(0)p.fillna(0, inplace=True)p[["1Sun", "2Mon", "3Tue", "4Wed", "5Thu", "6Fri", "7Sat"]] = p[["1Sun", "2Mon", "3Tue", "4Wed", "5Thu", "6Fri", "7Sat"]].astype(int)
It has always been working until the csv file doesn't have enough coverage (of all week days). For e.g., with the following .csv file,
DOW,Hour,Changes4Wed,01,2373Tue,07,25331Sun,01,2403Tue,12,44071Sun,09,22041Sun,01,2401Sun,01,2411Sun,01,2413Tue,11,6624Wed,01,42Mon,18,47371Sun,15,2402Mon,02,46Fri,01,11Sun,01,2402Mon,19,23002Mon,19,2532
I'll get the following error:
KeyError: "['5Thu''7Sat'] not in index"
It seems to have a very easy fix, but I'm just too new to Python to know how to fix it.