【发布时间】:2020-05-12 05:43:02
【问题描述】:
我有一些 Pandas /cudf 代码使用两种聚合方法聚合特定列,然后将多索引列重命名为扁平列。
df = (
some_df
.groupby(["some_dimension"])
.agg({"some_metric" : ["sum", "max"]})
.reset_index()
.rename(columns={"some_dimension" : "some_dimension__id", ("some_metric", "sum") : "some_metric_sum", ("some_metric", "max") : "some_metric_max"})
)
这在 cudf 中效果很好,但在 Pandas 0.25 中不起作用——层次结构没有变平。
是否有使用 Pandas 的类似方法?我喜欢 cudf 元组语法以及它们如何隐式地展平列。希望在 Pandas 中找到类似的简单方法。
谢谢。
【问题讨论】:
标签: pandas