简体   繁体   中英

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

I want to plot a column information as a pie chart. How to make it?

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

This pie chart should consist of 12 different values with their frequency.

Here is the easiest way

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

Here is one with 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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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