KeyError: 1738 while using for loop in python

Viewed 106

enter image description here Goal is data cleaning using stop words, stemming, etc . I have a list of statement so I am using for loop to go through each row to do data cleaning. If i try to do the steps on a single row its working fine but when i try to use for loop it throws KeyError.

code:

corpus = []
for i in range(0, 2000):
  action = re.sub('[^a-zA-Z]', ' ', data1['Action'][i])
  action = action.lower()
  action = action.split()
  ps = PorterStemmer()
  action = [ps.stem(word) for word in action if not word in set(stopwords.words('english'))]
  action = ' '.join(action)
  corpus.append(action)

error:

Traceback (most recent call last):

  File "<ipython-input-44-86c3af9b2191>", line 2, in <module>
    action = re.sub('[^a-zA-Z]', ' ', data1['Action'][i])

  File "C:\Users\bcpuser\anaconda3\lib\site-packages\pandas\core\series.py", line 871, in __getitem__
    result = self.index.get_value(self, key)

  File "C:\Users\bcpuser\anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 4405, in get_value
    return self._engine.get_value(s, k, tz=getattr(series.dtype, "tz", None))

  File "pandas\_libs\index.pyx", line 80, in pandas._libs.index.IndexEngine.get_value

  File "pandas\_libs\index.pyx", line 90, in pandas._libs.index.IndexEngine.get_value

  File "pandas\_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc

  File "pandas\_libs\hashtable_class_helper.pxi", line 997, in pandas._libs.hashtable.Int64HashTable.get_item

  File "pandas\_libs\hashtable_class_helper.pxi", line 1004, in pandas._libs.hashtable.Int64HashTable.get_item

KeyError: 1738

I believe its some kind of syntax error ?

0 Answers
Related