[Python] Any strategy to "link" 2 or more dataframes so transformations in one reflects in the...

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

  1. Stack

    Stack Membro Participativo

    Any strategies to "link" 2 (or more) dataframes so transformations in one dataframe reflects in the others?. For example:

    #Creating a 3x3 DataFrame with integers
    data = {
    'A': [1, 4, 7],
    'B': [2, 5, 8],
    'C': [3, 6, 9]
    }

    df1 = pd.DataFrame(data)

    A B C
    0 1 2 3
    1 4 5 6
    2 7 8 9

    #Creating a 3x3 DataFrame with strings

    data = {
    'A': ['apple', 'banana', 'cherry'],
    'B': ['dog', 'elephant', 'fox'],
    'C': ['grape', 'honeydew', 'kiwi']
    }

    df2 = pd.DataFrame(data)

    A B C
    0 apple dog grape
    1 banana elephant honeydew
    2 cherry fox kiwi


    For example sorting df1 from higher to slower in first row.

    df1:
    A B C
    0 3 2 1
    1 4 5 6
    2 7 8 9

    df2 should automatically be:
    A B C
    0 grape dog apple
    1 banana elephant honeydew
    2 cherry fox kiwi


    How one can get these "linked" objects? Is it possible with dataframes or dictionaries or another strategy? I have been doing it with tuples but maybe is there is a more clear straightforward way Thanks

    Continue reading...

Compartilhe esta Página