按小组按1/0数据计数的条形图

发布于 2025-02-13 14:11:45 字数 1158 浏览 2 评论 0原文

我完全很困难,没有人问。

我有一个类似于以下大大要大得多的熊猫数据框架,我想做的就是为每个地区创建一个条形图,显示出存在多少只鸟,即该列中有多少个'1。 “ 1的立场”,“不存在”,“ 0”。

Groupby District给了我胡说八道。

我敢肯定这是完全显而易见的事情,但是我在画一张空白。

区域1吞咽吞咽sparrowsparrowfinch
aaaa_1201010 001
aaaa_1201111 11 1 1 0 1 aaa a_1 2015 2015 2015 01
111111 1 1 11
1 AAAA_22011101 1 11
BBBB_120090 0 0 0 0 0 0 0 0 0 00 0 000
BBB1 1 AAA A_220091 1 1 11 1 11 11 1
BBBB_120120010

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.

districtareayearswallowsparrowkitefinch
aaaa_120101001
aaaa_120111101
aaaa_120150111
aaaa_220091111
aaaa_220111000
bbbb_120091111
bbbb_120120010

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请持续率性 2025-02-20 14:11:45

不确定您期望哪个确切的图形。这里有一些提示。

Per District/Bird:

(df
 .drop(columns=['area', 'year'])
 .groupby('district').sum()
 .plot.bar()
)

“在此处输入图像描述”

每个地区,所有鸟:

(df
 .drop(columns=['area', 'year'])
 .groupby('district').sum().sum(1)
 .plot.bar()
)

Not sure which exact graph you expect. Here are a few hints.

Per district/bird:

(df
 .drop(columns=['area', 'year'])
 .groupby('district').sum()
 .plot.bar()
)

enter image description here

Per district, all birds:

(df
 .drop(columns=['area', 'year'])
 .groupby('district').sum().sum(1)
 .plot.bar()
)

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文