[Python] How can I iterate over rows in a Pandas DataFrame?

Discussão em 'Python' iniciado por Stack, Janeiro 18, 2025.

  1. Stack

    Stack Membro Participativo

    I have a pandas dataframe, df:

    c1 c2
    0 10 100
    1 11 110
    2 12 120


    How do I iterate over the rows of this dataframe? For every row, I want to access its elements (values in cells) by the name of the columns. For example:

    for row in df.rows:
    print(row['c1'], row['c2'])


    I found a similar question, which suggests using either of these:


    • for date, row in df.T.iteritems():

    • for row in df.iterrows():

    But I do not understand what the row object is and how I can work with it.

    Continue reading...

Compartilhe esta Página