How can I build a pie chart using Pandas with this data

I have data like this

ID Sex Smoke 1 female 1 2 male 0 3 female 1 

How to make a circle chart to show how many men or women smokers?

+9
source share
3 answers

Suppose you start with:

 import pandas as pd from matplotlib.pyplot import pie, axis, show df = pd.DataFrame({ 'Sex': ['female', 'male', 'female'], 'Smoke': [1, 1, 1]}) 

You can always do something like this:

 sums = df.Smoke.groupby(df.Sex).sum() axis('equal'); pie(sums, labels=sums.index); show() 

enter image description here

+9
source

You can directly select the pie graph using pandas:

 import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame({'Sex': ['female', 'male', 'female'], 'Smoke': [1, 3, 1]}) df.Smoke.groupby(df.Sex).sum().plot(kind='pie') plt.axis('equal') plt.show() 

enter image description here

+4
source

here is one insert:

 temp[temp.Smoke==1]['Sex'].value_counts().plot.pie() 
0
source

All Articles