Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

iterate over dataframe

# 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])
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #iterate #dataframe
ADD COMMENT
Topic
Name
8+2 =