How do I plot a pie chart using Pandas with this data
You can plot directly with pandas selecting pie
chart:
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()
Say 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()