Im使用此对值进行分组:
代码:
df['new_carat'] = pd.cut(x=df['carat'], bins=[0, 0.49, 0.69, 0.99, 1.99, 3],
labels=['<0.5', '0.5-0.69', '0.7-0.99', '1-1.99', '>2'])
但当我试图绘制折线图时,它给了我问题。
代码:
ax1 = sns.countplot(x='new_carat', data = df, palette='husl')
ax1.set_xlabel('Carat')
ax1.set_ylabel('Count')
ax1.set_title('Carat Count & Avg Price')
ax2 = ax1.twinx()
ax2 = sns.lineplot("new_carat",'price', data = df, color = red)
ax2.set_ylabel('Average Price')
plt.show
错误消息说";ConversionError:无法将值转换为轴单位";
将线图更改为点图,解决了我的问题。
ax1 = sns.countplot(x='new_carat', data = df, palette='husl')
ax1.set_xlabel('Carat')
ax1.set_ylabel('Count')
ax1.set_title('Carat Count & Avg Price')
ax2 = ax1.twinx()
ax2 = sns.pointplot(x="new_carat", y='price', data = df, color = 'red')
ax2.set_ylabel('Average Price')
plt.show