title: Python: KeyError whet trying to print the value of a pandas series element
body: <p>I want to run a machine learning classifier. It works well. But when I am trying to  print the value of a test array , it says key error. Key error normally shows when the metadata is not present. But here you can see the y_test[index] exists.</p>
  
  <pre><code>data = pd.read_csv("fakenews.csv")
  #print(data)
  text = data.text
  label = data.label
  x_train, x_test, y_train, y_test = train_test_split(text,label,test_size=0.30)
  
  tfidf_vector = TfidfVectorizer(max_df=0.7)
  tfidf_train = tfidf_vector.fit_transform(x_train)
  tfidf_test = tfidf_vector.transform(x_test)
  
  from sklearn.naive_bayes import GaussianNB
  clf_nav = GaussianNB()
  clf_nav.fit(tfidf_train.todense(),y_train)
  print(clf_nav.predict(tfidf_test[1].todense()))
  print(y_test[0])
  test_score = accuracy_score(clf_nav.predict(tfidf_test.todense()),y_test)
  </code></pre>
  
  <p>and the error : </p>
  
  <pre><code>---------------------------------------------------------------------------
  KeyError                                  Traceback (most recent call last)
  &lt;ipython-input-10-87eea68c37cc&gt; in &lt;module&gt;()
        3 clf_nav.fit(tfidf_train.todense(),y_train)
        4 print(clf_nav.predict(tfidf_test[1].todense()))
  ----&gt; 5 print(y_test[0])
        6 test_score = accuracy_score(clf_nav.predict(tfidf_test.todense()),y_test)
        7 print(test_score*100)
  
  /usr/local/lib/python3.6/dist-packages/pandas/core/series.py in __getitem__(self, key)
      621         key = com._apply_if_callable(key, self)
      622         try:
  --&gt; 623             result = self.index.get_value(self, key)
      624 
      625             if not is_scalar(result):
  
  /usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py in get_value(self, series, key)
     2558         try:
     2559             return self._engine.get_value(s, k,
  -&gt; 2560                                           tz=getattr(series.dtype, 'tz', None))
     2561         except KeyError as e1:
     2562             if len(self) &gt; 0 and self.inferred_type in ['integer', 'boolean']:
  
  pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
  
  pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_value()
  
  pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()
  
  pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
  
  pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.Int64HashTable.get_item()
  
  KeyError: 0
  </code></pre>