[Python] How to update and extend dataframe1 with values from dataframe2

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

  1. Stack

    Stack Membro Participativo

    I have a dataframe df_old that I want to update with new values from df_new. The dataframes have exactly the same structure, each has records with a first column 'DateTime' that serves as the key column. The result should be a dataframe that is basically a concatenation of df_old and df_new but for every duplicate key only the new record (from df_new) is kept. How can i accomplish this?

    df_old:

    DateTime B C

    2024-09-21 12.9 5.4
    2024-09-22 13.1 5.4


    df_new:

    DateTime B C

    2024-09-22 13.2 5.2
    2024-09-23 13.4 4.9


    df_updated:

    DateTime B C

    2024-09-21 12.9 5.4
    2024-09-22 13.2 5.2 <-- new values overwrite the old ones
    2024-09-23 13.4 4.9

    Continue reading...

Compartilhe esta Página