小编Lau*_*ach的帖子

带条件的 groupby() - 计数/平均值

我有数据框:

test = pd.DataFrame({'Date': [2020 - 12 - 30, 2020 - 12 - 30, 2020 - 12 - 30, 2020 - 12 - 31, 2020 - 12 - 31, 2021 - 0o1 - 0o1, 2021 - 0o1 - 0o1], 'label': ['Positive', 'Positive', 'Negative', 'Negative','Negative', 'Positive', 'Positive'], 'score': [70, 80, 50, 50, 30, 90, 70]})
Run Code Online (Sandbox Code Playgroud)

输出:

   Date         label       score
2020-12-30      Positive    70
2020-12-30      Positive    80
2020-12-30      Negative    50
2020-12-31      Negative    50
2020-12-31      Negative    30
2021-01-01      Positive    90
2021-01-01      Positive    70
Run Code Online (Sandbox Code Playgroud)

我的目标是按日期分组并计算标签数。此外,分数应该仅计算当天较高的标签/分数的平均值。例如,如果当天的积极分数多于消极分数,则应计算没有消极分数的积极分数的平均值,反之亦然。 …

python group-by conditional-formatting pandas

5
推荐指数
1
解决办法
69
查看次数

标签 统计

conditional-formatting ×1

group-by ×1

pandas ×1

python ×1