1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] pandas- merge to datasets with diff col names adding values from the second into the...

Discussão em 'Python' iniciado por Stack, Setembro 12, 2024.

  1. Stack

    Stack Membro Participativo

    I have a couple of dataframes:

    DTime A B C
    2023-02-21 00:00:01 0 0 0
    2023-02-21 00:00:02 0 1 0
    2023-02-21 00:00:03 0 0 2
    2023-02-21 00:00:04 4 2 0


    DTime AAA BBB CC DDD EE
    2023-02-21 00:00:01 0 0 0 1 0
    2023-02-21 00:00:02 0 1 0 0 0
    2023-02-21 00:00:03 0 0 2 0 1
    2023-02-21 00:00:04 1 0 0 0 0


    I need to merge the first into the second where I explicitly map the cols and sum the values. i.e. - I want A to sum into AAA, B into BBB and C into CCC:

    DTime AAA BBB CC DDD EE
    2023-02-21 00:00:01 0 0 0 1 0
    2023-02-21 00:00:02 0 2 0 0 0
    2023-02-21 00:00:03 0 0 4 0 1
    2023-02-21 00:00:04 5 2 0 0 0


    I can't seem to make this happen without going line-by-line... But there must be a better way since I have thousands of rows and hundreds of cols.

    Continue reading...

Compartilhe esta Página