python - How to iterate over rows in a DataFrame in Pandas? -
i have dataframes pandas:
import pandas 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 want iterate on rows of above frame. every row want able access elements (values in cells) name of columns. so, example, have that:
for row in df.rows: print row['c1'], row['c2']
is possible in pandas?
i found similar question. not give me answer need. example, suggested there use:
for date, row in df.t.iteritems():
or
for row in df.iterrows():
but not understand row
object , how can work it.
iterrows generator yield both index , row
in [18]: index, row in df.iterrows(): ....: print row['c1'], row['c2'] ....: 10 100 11 110 12 120
Comments
Post a Comment