[Python] Pandas Merge duplicate index into single index

Discussão em 'Python' iniciado por Stack, Dezembro 8, 2024.

  1. Stack

    Stack Membro Participativo

    I have a simple data frame like this:

    d1={'a':{'1998-01-01':10}}
    d2={'b':{'1998-01-01':3}}

    df=pd.DataFrame.from_dict(d1)
    df=df.append(pd.DataFrame.from_dict(d2))
    df.index=pd.to_datetime(df.index)

    a b
    1998-01-01 10 NaN
    1998-01-01 NaN 3


    I would like to have

    a b
    1998-01-01 10 3


    Since 1998-01-01 share the index

    Continue reading...

Compartilhe esta Página