排序和限制要在条形图上显示的条形数量 [英] Sort and limit number of bars to display on bargraph

查看:68
本文介绍了排序和限制要在条形图上显示的条形数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个交通违规数据集,只想在条形图上仅显示每月排名前10的违规.在对值进行排序后是否可以限制小节的数量以仅显示前10个?有42个不同的流量违规列名.

I have a dataset of traffic violations and want to display only the top 10 violations per month on a bargraph. Can I limit the number of bars after sorting values to display only the top 10? There are 42 different column names of traffic violations.

month_jan = df[df.MonthName == "Jan"]
month_jan[feature_cols].sum().sort_values(ascending=0).plot(kind='bar')

Feature_cols是与交通违规相对应的所有42个列名称的列表.

Feature_cols is a list of all 42 column names that correspond to traffic violations.

谢谢!

推荐答案

这将起作用:

month_jan[feature_cols].sum().sort_values(ascending=0)[:10].plot(kind='bar')

这篇关于排序和限制要在条形图上显示的条形数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆