按小组按1/0数据计数的条形图
我完全很困难,没有人问。
我有一个类似于以下大大要大得多的熊猫数据框架,我想做的就是为每个地区创建一个条形图,显示出存在多少只鸟,即该列中有多少个'1。 “ 1的立场”,“不存在”,“ 0”。
Groupby District给了我胡说八道。
我敢肯定这是完全显而易见的事情,但是我在画一张空白。
区域 | 1 | 年 | 吞咽吞咽 | sparrow | sparrow | finch |
---|---|---|---|---|---|---|
aaa | a_1 | 2010 | 1 | 0 0 | 0 | 1 |
aaa | a_1 | 2011 | 1 | 1 1 | 1 1 1 0 1 aaa a_1 2015 2015 2015 0 | 1 |
1 | 1 | 1 | 1 | 1 | 1 1 1 1 | 1 |
1 AAA | A_2 | 2011 | 1 | 0 | 1 1 1 | 1 |
BBB | B_1 | 2009 | 0 0 0 0 0 0 0 0 0 0 0 | 0 0 0 | 0 | 0 |
BBB | 1 1 AAA A_2 | 2009 | 1 1 1 1 | 1 1 1 | 1 1 | 1 1 |
BBB | B_1 | 2012 | 0 | 0 | 1 | 0 |
I'm completely stumped and have no-one to ask.
I have a pandas dataframe similar to the following just much larger, what I would like to do is create a bar graph for each district that shows how many birds were present, i.e. how many '1's there are in the column. The '1's stand for 'was present', '0' for 'not present'.
groupby district gives me nonsense numbers.
I'm sure it is something completely obvious, but I'm drawing a blank.
district | area | year | swallow | sparrow | kite | finch |
---|---|---|---|---|---|---|
aaa | a_1 | 2010 | 1 | 0 | 0 | 1 |
aaa | a_1 | 2011 | 1 | 1 | 0 | 1 |
aaa | a_1 | 2015 | 0 | 1 | 1 | 1 |
aaa | a_2 | 2009 | 1 | 1 | 1 | 1 |
aaa | a_2 | 2011 | 1 | 0 | 0 | 0 |
bbb | b_1 | 2009 | 1 | 1 | 1 | 1 |
bbb | b_1 | 2012 | 0 | 0 | 1 | 0 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定您期望哪个确切的图形。这里有一些提示。
Per District/Bird:
每个地区,所有鸟:
Not sure which exact graph you expect. Here are a few hints.
Per district/bird:
Per district, all birds: