[Python] Interpolate among Groups in pandas DataFrame

Discussão em 'Python' iniciado por Stack, Junho 16, 2025.

  1. Stack

    Stack Membro Participativo

    I'm looking for the most efficient way to interpolate across Groups in pandas DataFrame for a big data volume. For example I have some groups that have all the values, and some that have none. In the example below data is groupby('Group'), Groups A and D have all the values at all Time, and Groups B,C and E have none.

    How to find the most efficient way to interpolate Group E based on Group D specifically, giving the logic that Group D is the nearest and thus to be used for interpolation.

    I am new to python.

    Group Time Value
    A 1 10
    A 2 15
    A 3 30
    A 4 50
    B 1 NaN
    B 2 NaN
    B 3 NaN
    B 4 NaN
    C 1 NaN
    C 2 NaN
    C 3 NaN
    C 4 NaN
    D 1 5
    D 2 10
    D 3 15
    D 4 20
    E 1 NaN
    E 2 NaN
    E 3 NaN
    E 4 NaN


    The expected output is something like the below

    Group Time Value
    A 1 10
    A 2 15
    A 3 30
    A 4 50
    B 1 10
    B 2 15
    B 3 30
    B 4 50
    C 1 5
    C 2 10
    C 3 15
    C 4 20
    D 1 5
    D 2 10
    D 3 15
    D 4 20
    E 1 5
    E 2 10
    E 3 15
    E 4 20

    Continue reading...

Compartilhe esta Página