[Python] sum columns in dataframe with pandas

Discussão em 'Python' iniciado por Stack, Janeiro 12, 2025.

  1. Stack

    Stack Membro Participativo

    I have a dataframe df_F1

    df_F1.info()

    <class 'pandas.core.frame.DataFrame'>
    Int64Index: 2 entries, 0 to 1
    Data columns (total 7 columns):
    class_energy 2 non-null object
    ACT_TIME_AERATEUR_1_F1 2 non-null float64
    ACT_TIME_AERATEUR_1_F3 2 non-null float64
    dtypes: float64(6), object(1)
    memory usage: 128.0+ bytes


    df_F1.head()

    class_energy ACT_TIME_AERATEUR_1_F1 ACT_TIME_AERATEUR_1_F3
    low 5.875550 431
    medium 856.666667 856


    I try to create a dataframe Ratio which contain for each class_energy the value of energy of each ACT_TIME_AERATEUR_1_Fx divided by the sum of energy of all class_energy for each ACT_TIME_AERATEUR_1_Fx. For example:


    ACT_TIME_AERATEUR_1_F1 ACT_TIME_AERATEUR_1_F3
    low 5.875550/(5.875550 + 856.666667) 431/(431+856)
    medium 856.666667/(5.875550+856.666667) 856/(431+856)​

    Can you help me please to resolve it?

    Continue reading...

Compartilhe esta Página