python:从熊猫枢轴的提取柱

发布于 2025-02-09 19:08:00 字数 309 浏览 2 评论 0原文

我有一个枢轴桌子 total_chart = df.pivot_table(index =“ name”,values =“ tock”,aggfunc ='count')> 输出使

A              8
B             52
C             24
D              6
E             43
F              5
G             13
I              1

我尝试仅获得第二列(仅数字) 有什么简单的方法吗?

I have a pivoted table
total_chart = df.pivot_table(index="Name", values="Items", aggfunc='count')
The output gives

A              8
B             52
C             24
D              6
E             43
F              5
G             13
I              1

I trying to get only the second column (number only)
Is there any simple way to get it?

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

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

发布评论

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

评论(1

意中人 2025-02-16 19:08:02

下面的代码应该为您带来技巧。
它计数“项目”,按索引“名称”排序,然后仅输出没有索引的计数。

df['Items'].value_counts().sort_index(ascending=True).tolist()

The code below should do the trick for you.
It counts "Items", sort it ascending by the index "Name" and output just the counts without the index.

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