[Python] Pandas groupBy multiple columns and aggregation (group by frequency and then by value)

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

  1. Stack

    Stack Membro Participativo

    I have the following data frame: enter image description here enter image description here

    ***>> gg = pd.DataFrame(
    {
    "Tool": [1 , 2 , 1 , 2, 2, 2, 1, 2, 1,2],
    "Timestamp": ['2022-05-28 05:03:00','2022-05-29 06:07:00','2022-05-28 07:11:00','2022-05-27 11:04:00','2022-05-27 05:43:00','2022-05-25 06:07:00','2022-05-28 11:22:00','2022-05-28 02:00:00','2022-05-26 04:22:00','2022-05-28 09:55:00'],
    "Sensor1": [10,11,12,13,6,7,3,11,8,9],
    "Sensor2": [5,4,3,3,5,4,3,3,8,2],
    "Sensor3": [1,2,3,6,1,2,3,6,4,5],
    }
    )
    >>gg.groupby(['Tool', 'Timestamp'])[['Sensor1', 'Sensor2', 'Sensor3']].mean()***


    But I'd like to group by the tool first and secondly group the sensor values by the same day (sensor value is mean value). Thanks

    Continue reading...

Compartilhe esta Página