python plot get_loc(self, key, method, tolerance) 错误

python plot get_loc(self, key, method, tolerance) error

我尝试用绘图过程制作饼图。

chad = pd.read_csv("Admission_Predict.csv", engine = 'python')
chad_2 = chad.drop(['Serial No'], axis = 1)
chad_2.head()

如下图所示:

enter image description here

f, ax = plt.subplots(1, 2, figsize=(18,8))

chad_2['Chance of Admit'].value_counts().plot.pie(explode =[0,0.1], labels = ['low', 'high'], colors = ['#0066cc', '#cc0000'], autopct='%1.1f%%', ax=ax[0], textprops = {'fontsize' : 40})

ax[0].set_title('Pie plot - Chance of Admit')

ax[0].set_ylabel('')

sns.countplot('Chance of Admit', data=chad_2, ax=ax[1], palette = "Set1")

ax[`1`].set_xticklabels(["low", "high"])

ax[`1`].set_title('Count plot - Chance of Admit')

plt.show()

但是,此代码的 return 显示以下错误...

我已经找到问题的答案了。该列末尾有空格。 所以我执行了 chad_2.columns = chad_2.columns.str.strip() 它奏效了!