[Python] How do I create a new column based on the maximum value found between several other...

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

  1. Stack

    Stack Membro Participativo

    Currently I'm using pandas and numpy to play around with a data set on rain measurements in India, however I'm stumped on trying to create a particular column. Currently my data set looks like this:

    SUBDIVISION​
    JAN​
    FEB​
    MAR​
    APR​
    MAY​
    Andaman & Nicobar Islands​
    50​
    70​
    90​
    250​
    430​
    Arunachal Pradesh​
    46​
    90​
    151​
    265​
    356​
    Assam & Meghalaya​
    16​
    31​
    79​
    505​
    340​
    Bihar​
    13​
    14​
    100​
    16​
    53​

    What I want is to replace all the columns that have the months with a single column "Months", and I want this column to contain the name of the month that has the most amount of rain, so for example it would look like this:

    SUBDIVISION​
    Months​
    Andaman & Nicobar Islands​
    MAY​
    Arunachal Pradesh​
    MAY​
    Assam & Meghalaya​
    APR​
    Bihar​
    MAR​

    My data set is much larger than this so trying to manually input all of the data would not be worth it.

    Continue reading...

Compartilhe esta Página