【问题标题】:Group By While Keeping All Cell Values在保留所有单元格值的同时分组
【发布时间】:2019-11-25 16:05:02
【问题描述】:

我了解带有 sum 作为 agg 函数的 groupby 类型执行以下操作:

之前:

type    stale   price      
orange    yes     1    
apple     yes     2     
orange    no      3   

之后:

type    stale   price      
orange    yes     1    
          no      3     
apple     no      2   

groupby 中是否有允许我显示所有单元格值的参数?因此在上面写着苹果的地方放置一个“橙色”的值,而不是强迫读者理解第二行仍然属于橙色?对于这个例子,它可能看起来没什么用,但在更大的数据集中,能够看到所有单元格的值会很有帮助。

【问题讨论】:

标签: python pandas group-by


【解决方案1】:

尝试重置索引:

grouped_dat.reset_index()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-13
    • 1970-01-01
    • 1970-01-01
    • 2018-03-23
    • 1970-01-01
    • 1970-01-01
    • 2023-01-16
    • 1970-01-01
    相关资源
    最近更新 更多