简体   繁体   中英

how to plot a pie chart from a dataframe using crosstab function in python

i am trying to plot a pie chart using crosstab function from 2 columns in a dataframe where until now i am able to plot a bar chart using the below statement.

sample of the dataframe:

在此处输入图像描述

pd.crosstab(df['event_location'],df['event_type']).iplot(kind="bar", bins=20, theme="white", title="Event type over Location",xTitle='location', yTitle='Number of person')

在此处输入图像描述

my question is how to convert this bar chart into a pie chart?

I guess you are trying to display the number of occurrences for every event type. This simple code will help you plot pie charts per location.

import matplotlib.pyplot as plt
ct = pd.crosstab(df['event_location'],df['event_type'])
ct.plot.pie(subplots=True)
plt.legend(title='XYZ')
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