【问题标题】:get the index of resulting grouped-by rows in pandas获取 pandas 中结果分组行的索引
【发布时间】:2022-06-11 15:58:30
【问题描述】:

我在我的数据框上做了一个groupby('column_name',axis=1).agg(sum),它是 20000 行。

编辑:我只想查看在 groupby 之前重复的行的索引,即在 groupby 列中具有相似值的所有行。我该怎么做?

(我问是因为我收到警告,我想检查我的 groupby 的结果

FutureWarning: Dropping invalid columns in DataFrameGroupBy.add is deprecated. In a future version, a TypeError will be raised. Before calling .add, select only columns which should be valid for the function.)

我已经尝试搜索论坛和谷歌,但我只得到 groupby 索引的结果。

【问题讨论】:

  • 请添加数据示例,分组依据是什么,分组后你想要什么?
  • 数据是 20000 行...我只在执行 pd.groupby('column_name').agg(sum) 或 agg(mean) 时要求一个命令来获取合并行的索引
  • 不清楚“获取合并行的索引”是什么意思(pd.groupby('column_name').agg(sum).index??)。一个包含数据子集的小例子可能有助于澄清这一点并激励人们发布答案。
  • pd.groupby('column_name').agg(sum).index 给出整个数据帧的索引,我只想要结果分组行的索引,我看不出有什么难理解的这里
  • 不,df.index 给出了整个数据帧的索引,df.groupby('...').sum().index 给出了聚合结果的索引。如果这不是你的意思,请帮助我理解,因为我真的不明白。通常,熊猫问题会在几分钟内得到答案——如果写得很清楚(参见this post)。

标签: python pandas


猜你喜欢
  • 1970-01-01
  • 2015-08-11
  • 2017-10-12
  • 1970-01-01
  • 1970-01-01
  • 2021-03-08
  • 2022-01-02
  • 2019-02-07
  • 1970-01-01
相关资源
最近更新 更多