[Python] Pandas insert row if value is missing

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

  1. Stack

    Stack Membro Participativo

    Simple one but tired brain is letting me see the solution. I can not pivot because there are repeat values in 'number'.

    pd.DataFrame({'KeyID':[1,1,1,1,2,2,2,3,3,3], 'number':['a','a','c','d','a','b','c','a','b','c']})


    I need each KeyID to have a 'd' if it does not then a row with NAN needs to be added. Both KeyId 2 and 3 are missing a 'd' so need a blank row adding.

    [​IMG]

    Continue reading...

Compartilhe esta Página