title: Trying to loop through a pandas dataframe and display specific values in a column
body: <p>So I'm trying to code a stroop task by looping through a preexisting .csv file. To do this I read the stimuli.csv file into a dataframe. </p>
  
  <p>The .csv file is organized like this: </p>
  
  <pre><code>  Colours   Congruent   Word
  0   red       0        blue
  1   red       1        red
  2   red       0        green
  3   blue      1        blue
  </code></pre>
  
  <p>I then try to loop through the dataframe checking values in the 'Colours' column and 'Words' column. Colours should be displayed as the font of the word so I check the indexed value in the Colour column to properly display the corresponding colour font. The word displayed itself should be the value indexed in the 'Word' column. I'm getting: </p>
  
  <p>Keyerror: 0 </p>
  
  <p>I've looked online but no specific examples help me. Can anyone tell me if i'm going about this all wrong? </p>
  
  <pre><code>import pygame
  import sys
  import psychopy
  import os
  import csv
  import pandas as pd 
  pygame.init()
  screen = pygame.display.set_mode((1000, 500))
  screen.fill((0, 0, 0))
  myfont= pygame.font.SysFont("Calibri", 30) 
  blue= (0,0,255)
  green= (0,255,0)
  red= (255,0,0)
  while 1: 
      file= r'stimuli.csv'
      df= pd.read_csv('%s' %file, delimiter=',', encoding="utf-8-sig")
      word= df['Word']                
      congruent= df['Congruent']
      colour= df['Colours']
      for index, row in df.iterrows():
          word= df[index].iloc['Word']                
          congruent= df[index].iloc['Congruent']
          colour= df[index].iloc['Colours']
          if df.iloc[index].iloc['Colours']== 'red':
              stim= myfont.render('%s' %word, 1, (255,0,0))
              screen.blit(stim, (300,300))
              pygame.display.flip()
          if df.iloc[index].iloc['Colours']== 'green':
              stim= myfont.render('%s' %word, 1, (0,255,0))
              screen.blit(stim, (300,300))
              pygame.display.flip()
          if df.iloc[index].iloc['Colours']== 'blue':
              stim= myfont.render('%s' %word, 1, (0,0,255))
              screen.blit(stim, (300,300))
              pygame.display.flip()
  
      for event in pygame.event.get(): 
          if event.type == pygame.KEYDOWN: 
              if event.key== pygame.K_ESCAPE: 
                  msg2= myfont.render("Exiting now", 1, (0, 255, 0))
                  screen.blit(msg2, (300, 300))
                  pygame.display.flip()
  
                  pygame.display.quit()   
  pygame.quit()
  </code></pre>