如何将一个.agg的结果用作另一个中的参数?

2024-03-28 14:02:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用一些基本的摘要函数在pandas dataframe中聚合一些数据,但是我需要一些这些摘要函数的函数

我目前正在做的是:

df_summary = df.groupby(['list', 'of', 'column', 'names'])['column to summarize'].agg(['sum', 'mean', 'some other functions'])
df_summary["other_summary1"] = df_summary["mean"] * constant1 + constant2
df_summary["other_summary2"] = math.log(df_summary["other_summary1"])

我的直觉告诉我,这不是惯用的方法,而且肯定有一种方法可以在.agg()中转换函数。有吗


Tags: 数据方法函数dataframepandasdfcolumnsummary