如何在python中从对象数据帧列绘制饼图



我想将列信息绘制为饼图。如何制作?

redemption_type = redemptions['redemption_type']
redemption_type.describe()
count     641493
unique        12
top       MPPAID
freq      637145
Name: redemption_type, dtype: object

这个饼图应该由12个不同的值及其频率组成。

以下是的最简单方法

redemptions['redemption_type'].value_counts().plot(kind='pie')

这是一个带有plotly-express

temp = pd.DataFrame(redemptions['redemption_type'].value_counts())
temp.index.name = 'val'
temp.columns = ['count']
temp = temp.reset_index()
temp
fig = px.pie(temp, names='val', values='count')
# fig.update_traces(textinfo='value') # uncomment this line if you want actual value on the chart instead of %
fig.show()

最新更新