[Python] How to resolve "ValueError: cannot reindex on an axis with duplicate labels" error...

Discussão em 'Python' iniciado por Stack, Maio 2, 2025.

  1. Stack

    Stack Membro Participativo

    cube timestamp temp
    timestamp
    2022-08-01 00:15:05.135 A1 2022-08-01 00:15:05.135 NaN

    2022-08-01 00:15:37.255 A1 2022-08-01 00:15:37.255 23.17

    2022-08-01 00:23:05.139 A1 2022-08-01 00:23:05.139 NaN

    2022-08-01 00:23:15.137 A1 2022-08-01 00:23:15.137 NaN

    2022-08-11 11:33:20.738 P19 2022-08-11 00:15:05.135 NaN


    I am trying to interpolate NaN value in temperature based on the timestamp with respect to the cubes by using the below code

    idata.set_index(idata['timestamp'],inplace = True)

    idata['temp'] = idata.groupby('cube')['temp'].apply(lambda x:x.interpolate(method="time",limit_direction = "both"))


    while executing this code, I am getting the error "ValueError: cannot reindex on an axis with duplicate labels". I cannot remove the duplicate labels(timestamp) as it may belong to different cubes. please suggest the alternative to handle this situation.

    Continue reading...

Compartilhe esta Página