FOREST
FOREST

Reputation: 338

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.

Upvotes: 2

Views: 1770

Answers (1)

imdevskp
imdevskp

Reputation: 2223

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

Upvotes: 3

Related Questions