Pandas > Iterate over data

Name
Code
Output
dataframe = pandas.DataFrame(numpy.random.randint(0,100,size=(3, 2)), columns=['C1','C2'])
print ("dataframe")
print (dataframe)
print (10*'-')
print ("Iteration \n")
for col_idx,data in dataframe.iteritems():
    print ("column:",col_idx)
    print ("column data:")
    print (data,"\n")
dataframe
   C1  C2
0  58  37
1  31   0
2  53  60
----------
Iteration 

column: C1
column data:
0    58
1    31
2    53
Name: C1, dtype: int64 

column: C2
column data:
0    37
1     0
2    60
Name: C2, dtype: int64
dataframe = pandas.DataFrame(numpy.random.randint(0,100,size=(3, 2)), columns=['C1','C2'])
print ("dataframe")
print (dataframe)
print (10*'-')
print ("Iteration \n")
for col_idx,data in dataframe.iteritems():
    print ("column:",col_idx)
    print ("column data:")
    print (data,"\n")
dataframe
   C1  C2
0  63  20
1  25  47
2  60  65
----------
Iteration 

column: C1
column data:
0    63
1    25
2    60
Name: C1, dtype: int64 

column: C2
column data:
0    20
1    47
2    65
Name: C2, dtype: int64
dataframe = pandas.DataFrame(numpy.random.randint(0,100,size=(3, 2)), columns=['C1','C2'])
print ("dataframe")
print (dataframe)
print (10*'-')
print ("Iteration \n")
for col_idx,data in dataframe.iterrows():
    print ("row:",col_idx)
    print ("row data:")
    print (data,"\n")
dataframe
   C1  C2
0  47  15
1  68  59
2   8  96
----------
Iteration 

row: 0
row data:
C1    47
C2    15
Name: 0, dtype: int64 

row: 1
row data:
C1    68
C2    59
Name: 1, dtype: int64 

row: 2
row data:
C1     8
C2    96
Name: 2, dtype: int64
dataframe = pandas.DataFrame(numpy.random.randint(0,100,size=(3, 2)), columns=['C1','C2'])
print ("dataframe")
print (dataframe)
print (10*'-')
print ("Iteration \n")
for data in dataframe.itertuples():
    print ("row data:")
    print (data,"\n")
dataframe
   C1  C2
0  39  89
1  54  76
2  93  34
----------
Iteration 

row data:
Pandas(Index=0, C1=39, C2=89) 

row data:
Pandas(Index=1, C1=54, C2=76) 

row data:
Pandas(Index=2, C1=93, C2=34)