title: IndexError: list index out of range when in python, even when the range exists
body: <p>I am sure that the range which I am trying to access exists, but still, the program shows error. I am trying to make a program which will sum up the values in a column corresponding to the values in the other column.</p>
  
  <p>for example:</p>
  
  <pre><code>   28400    4
     28400    34 
     28400    9
     65478    2
     65478    5
     65478    3
  </code></pre>
  
  <p>what my program will do is, it will add up 4,34 and 9 and then it will add up 2,5 and 3 and then following will be the output-</p>
  
  <pre><code>   47
     47
     47
     10
     10
     10  
  </code></pre>
  
  <p>I am importing data from a CSV file. following is the code-</p>
  
  <pre><code>    import pandas as pd
      import numpy as np
  
      assessment = pd.read_csv('/home/user/Documents/MOOC dataset original/studentVle2.csv')
  
  
      assessment = assessment.values
  
      count=0
      stucount=28400
      sumc=[]
      i=0
      for stu in assessment[:,2:3]:
          if(stucount==stu):
              count = count + assessment[i,5]
              i=i+1
          else:
              sumc.append(count)
              count = 0
              count = count + assessment[i,5]
              i=i+1
          stucount=stu
  
      #print(sumc)
  
      stucount=28400
      i=0
      a=[]
      for stu in assessment[:,2:3]:
          if(stucount==stu):
              a.append(sumc[i])
              stucount = stu
          else:
              i=i+1
              a.append(sumc[i])
              stucount = stu
  
      print(a)
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>        File "/home/user/Documents/final project files/test.py", line 36, in &lt;module&gt;
          a.append(sumc[i])
          IndexError: list index out of range
  </code></pre>
  
  <p>and by the way, before adding some lines, like i=i+1,stucount=stu this error was not shown, but now it shows even though what happening is the same.</p>