gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 08:44:14 25 4
gpt4 key购买 nike

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

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()

但是,此代码的返回结果显示以下错误...

最佳答案

我已经回答了我的问题。该列的末尾有空格。
所以我执行了chad_2.columns = chad_2.columns.str.strip()
而且有效!

关于python - python plot get_loc(self,key,method,tolerance)错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58223704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com