[Python] how to get non-aggregate columns using pandas using group by

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

  1. Stack

    Stack Membro Participativo

    I have sample data frame like this

    Id application is_a is_b is_c reason subid record
    100 app_1 False False False test1 4 record100
    100 app_2 True False False test2 3 record100
    100 app_3 True True False test3 5 record100
    101 app_1 False False False test1 3 record101
    101 app_2 True False False test2 4 record101


    After applying group by with Id along with concat of application and max value of of columns starts wth is_ columns and max of subid resultant dataframe like below

    Id application is_a is_b is_c subid
    100 app_1,app2,app_3 True True False 5
    101 app_1,app2 True False False 4


    I'm looking for non-aggregared columns reason and record as well it should match with subid like below

    Id application is_a is_b is_c subid reason record
    100 app_1,app2,app_3 True True False 5 test3 record100
    101 app_1,app2 True False False 4 test2 record101


    what is the best way to deal with pandas to get the above solution? I appreciate your help on this.

    Continue reading...

Compartilhe esta Página