繁体   English   中英

如何 plot 从 object dataframe 列中的 Z23EEEB4347BDD2576BFC6B7EE9AB 中的饼图?

[英]How to plot a pie chart from an object dataframe column in python?

我想将 plot 的一列信息作为饼图。 怎么做?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM