简体   繁体   English

如何使用 python 中的交叉表 function 从 dataframe 获得饼图 plot

[英]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.我正在尝试使用 dataframe 中 2 列的交叉表 function 制作饼图 plot,直到现在我能够使用以下语句制作 plot 条形图。

sample of the dataframe: 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.这个简单的代码将帮助您每个位置 plot 个饼图。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM