# Option 1
for row in df.iterrows():
print row.loc[0,'A']
print row.A
print row.index()
# Option 2
for i in range(len(df)) :
print(df.iloc[i, 0], df.iloc[i, 2])
# Method A for single column dataframe
cell = list()
for i in range(len(df)):
cell_value=df.iloc[i][0]
cell.append(cell_value)
# Method B for multiple column dataframe
for index, row in df.iterrows():
print(row["c1"], row["c2"])
# Method C
columns = list(df.columns)
for i in columns:
print (df[i][2])
# importing pandas as pd
import pandas as pd
# dictionary of lists
dict = {'name':["aparna", "pankaj", "sudhir", "Geeku"],
'degree': ["MBA", "BCA", "M.Tech", "MBA"],
'score':[90, 40, 80, 98]}
# creating a dataframe from a dictionary
df = pd.DataFrame(dict)
# iterating over rows using iterrows() function
for i, j in df.iterrows():
print(i, j)
print()
import pandas as pd
df = pd.DataFrame({'c1': [10, 11, 12], 'c2': [100, 110, 120]})
df = df.reset_index() # make sure indexes pair with number of rows
for index, row in df.iterrows():
print(row['c1'], row['c2'])