简体   繁体   中英

creating Pie chart for my dataframe for a single column with percentage

import pandas as pd 
data = [['tim', 1], ['nick', 1], ['dick', 0]] 
df = pd.DataFrame(data, columns = ['Name', 'EMI_Paid']) 
df 

My dataframe has two columns: "Name" and "EMI_Paid" and I want plot a pie chart for column "EMI paid". The column "EMI_Paid" can have two values: 0 and 1.

Here 1 means - Customer Paid the EMI and 0 means EMI not yet received. I want to show the percentage of total no of people paid the EMI and not yet paid. and also I want change the label in the pie chart instead of 1 & 0 I want to display as below for 1- EMI paid and for 0- Payment not yet received.

Code I have used

df.groupby('EMI_Paid').size().plot(kind='pie', legend=True)

You can do :

import matplotlib.pyplot as  plt
df.plot.pie(y='EMI_Paid', figsize=(5,5),labels=df['Name'])
plt.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