1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Update a dataframe in pandas while iterating row by row

Discussão em 'Python' iniciado por Stack, Outubro 7, 2024 às 12:52.

  1. Stack

    Stack Membro Participativo

    I have a pandas data frame that looks like this (its a pretty big one)

    date exer exp ifor mat
    1092 2014-03-17 American M 528.205 2014-04-19
    1093 2014-03-17 American M 528.205 2014-04-19
    1094 2014-03-17 American M 528.205 2014-04-19
    1095 2014-03-17 American M 528.205 2014-04-19
    1096 2014-03-17 American M 528.205 2014-05-17


    now I would like to iterate row by row and as I go through each row, the value of ifor in each row can change depending on some conditions and I need to lookup another dataframe.

    Now, how do I update this as I iterate. Tried a few things none of them worked.

    for i, row in df.iterrows():
    if <something>:
    row['ifor'] = x
    else:
    row['ifor'] = y

    df.ix['ifor'] = x


    None of these approaches seem to work. I don't see the values updated in the dataframe.

    Continue reading...

Compartilhe esta Página