擅长:python、mysql、java
<p>Pandas支持自动将每个列打印到子图中。因此,您希望选择<code>CityName</code>作为索引,将<code>EventCode</code>作为列和绘图</p>
<pre><code>(df.sort_values('EventCount', ascending=False) # sort descending by `EventCount`
.groupby('EventCode', as_index=False)
.head(5) # get 5 most count within `EventCode`
.pivot(index='CityName', # pivot for plot.pie
columns='EventCode',
values='EventCount'
)
.plot.pie(subplots=True, # plot with some options
figsize=(10,6),
layout=(2,3))
)
</code></pre>
<p>输出:</p>
<p><a href="https://i.stack.imgur.com/jOMaj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jOMaj.png" alt="enter image description here"/></a></p>