[Python] Find column name with highest value [duplicate]

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

  1. Stack

    Stack Membro Participativo

    On the Pandas dataframe below I use max to find the maximum value:

    df["Max"] = df[['Day 1','Day 2','Day 4']].max(axis=1)

    Car Day 1 Day 2 Day 4 Max
    Car1 4 7 3 7
    car2 8 2 1 8

    What do I do to find when is the maximum value instead of the value itself as the table example below?

    Car Day 1 Day 2 Day 4 When
    Car1 4 7 3 Day 2
    car2 8 2 1 Day 1

    Continue reading...

Compartilhe esta Página