python - 从 Pandas GroupBy 函数中提取结果
问题描述
我对 Python 比较陌生,并开始使用 Pandas。我查看了 Pandas 文档,但找不到我需要的东西,尽管这可能是由于不熟悉某些术语。
我使用了 Dataframe GroupBy 函数并得到了这些结果
mean_len = spam.groupby(spam.target).mean()
Function Mean
A 1.5
B 2.6
我的问题是,什么代码会从 groupby 输出生成以下结果:
(1.5, 2.6)
多谢
解决方案
You can extract the series Mean as a numpy array using
means = mean_len.Mean.values
If what you actually want is a list or a tuple, you can additionally do
tuple(means.tolist())
推荐阅读
- node.js - 如何在 GCP 中部署 AngularJS?
- php - 试图获取非对象后端\students\contact.blade.php 的属性“profile_picture”
- python - Pyhive+Pandas:TTransportException:TSocket 在运行查询大量行时读取 0 个字节(>1000)
- go - 用价值方法修改接收器?
- c# - Entity Framework Core:插入时出现错误?
- powershell - 有没有办法在我的域中找到监视器?
- python-3.x - 如何在格式化的字符串 python3 中进行换行
- windows - 如何使用 Windows 批处理文件将所选文件移动到特定文件夹?
- xmlhttprequest - 在发出 XMLHttpRequest 后,是什么让代码继续运行?
- python - 是什么导致消息“IndexError:列表索引超出范围”?