title: Caught In Potential Infinite Loop
body: <p>I am simply trying to make a list of district names and District objects from a pandas DataFrame, but for some reason, the code never finishes running. I can't see anywhere that could become an infinite loop, so it is beyond me as to why it gets stuck every time I run it. Here is the section that is getting stuck (particularly the j-iterated for loop):</p>
  
  <pre><code>import numpy as np
  import pandas as pd
  
  #make dataframe
  data = pd.read_csv('gun-violence-data_01-2013_03-2018.csv', header=0, delimiter=',')
  
  #drop data points with null condressional district values
  data = data[data.congressional_district != 0]
  data.dropna(axis=0,how='any',subset=['congressional_district'],inplace= True)
  
  #constructing working table
  table = data[['incident_id','state','congressional_district']]
  
  #list of districts. Formatting in original file must be corrected to analyze data
  districtNames = ['filler1','filler2']
  districts = []
  s = table.shape
  
  #loop thru the rows of the table
  for i in range(s[0]):
      check = True
  
      #build strings for each district
      ds = table.iloc[i,1] + str(table.iloc[i,2])
      #testString = str(table.iloc[i,2])
  
      #append ds to districtNames if it isnt in already
      #make array of District Objects
      for j in range(len(districtNames)):
          if(ds == districtNames[j]):
              check = False
          if(check):
              districtNames.append(ds)
              districts.append(District(ds,0))
  </code></pre>
  
  <p>For reference, here is the District class:</p>
  
  <pre><code>class District:
  def __init__(self, name, count):
      self._name = name
      self._count = count
  def get_name(self):
      return name
  def get_count(self):
      return count
  def updateCount(self,amount):
      self._count += amount
  </code></pre>
  
  <p>The initial .csv file is quite large, and after cutting out some of the data points in the 8th and 9th lines, I have 227,312 data points left. I understand this is quite a few, but the code doesn't even finish after running for 5 minutes. What am I doing wrong?</p>