Cindy B.

asked • 05/16/18

How to iterate over rows in a DataFrame in Pandas?

I have a DataFrames from pandas:
import pandas as pd
inp = [{'c1':10, 'c2':100}, {'c1':11,'c2':110}, {'c1':12,'c2':120}]
df = pd.DataFrame(inp)
print df
Output:
c1 c2
0 10 100
1 11 110
2 12 120
Now I want to iterate over the rows of the above frame. For every row I want to be able to access its elements (values in cells) by the name of the columns. So, for example, I would like to have something like that:
for row in df.rows:
print row['c1'], row['c2']
Is it possible to do that in pandas?

1 Expert Answer

By:

Erik W. answered • 05/16/18

Tutor
5 (11)

Finance and Statistics Professional with Real World Experience

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.