[Python] Aggregating in pandas groupby using lambda functions

Discussão em 'Python' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    I have an aggregation statement below:

    data = data.groupby(['type', 'status', 'name']).agg({
    'one' : np.mean,
    'two' : lambda value: 100* ((value>32).sum() / reading.mean()),
    'test2': lambda value: 100* ((value > 45).sum() / value.mean())
    })


    I get KeyErrors. I have been able to make it work for one lambda function but not two.

    Continue reading...

Compartilhe esta Página