For Row In Column Pandas Code Example

Snippet 1

  # 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])  

Snippet 2

  df = pd.DataFrame([{'c1':10, 'c2':100}, {'c1':11,'c2':110}, {'c1':12,'c2':120}])
for index, row in df.iterrows():
    print(row['c1'], row['c2']) 

Copyright © Code Fetcher 2020

 

 

Leave a comment

Your email address will not be published. Required fields are marked *