python keyerror not in index_Pandas KeyError:值不在索引中

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,Changes

4Wed,01,237

3Tue,07,2533

1Sun,01,240

3Tue,12,4407

1Sun,09,2204

1Sun,01,240

1Sun,01,241

1Sun,01,241

3Tue,11,662

4Wed,01,4

2Mon,18,47

你可能感兴趣的:(python,keyerror,not,in,index)