title: KeyError "[.....]" not in index
body: <p>I am working on a project for work and was handed this code after having no previous experience with Python. I'm getting a KeyError message, and the line above that has some red text that I am also unsure about. Here's the exact text: </p>
  
  <pre><code>  File "/anaconda3/lib/python3.7/site-packages/pandas/core/indexing.py", line 1327, in _convert_to_indexer
      .format(mask=objarr[mask]))
  
  KeyError: "['First name' 'Last name' 'Company' 'Email address - other' 'Opened At'\n 'Company.1'] not in index"
  </code></pre>
  
  <p>I have been looking into tutorials all day and understand that this is an issue with the fact that this DataFrame doesn't have an index, but I think that is due to the fact that it is importing data from a file that doesn't have a set name. </p>
  
  <p>Here's the beginning portion of the code that I believe has the issue: </p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import glob, os
  import re
  
  # In[21]:
  db = pd.DataFrame()
  for file in glob.glob("report_*.csv"):
      df = pd.read_csv(file, encoding = "ISO-8859-1")
      db = db.append(df,ignore_index=True)
  
  # In[22]:
  db= db[['First name','Last name', 'Company', 'Email address - other','Opened At','Company.1']]
  
  # In[23]:
  db.columns = [c.replace(' ', '_') for c in db.columns]
  db.columns = [c.replace('-', '_') for c in db.columns]
  db.columns = [c.replace('.', '_') for c in db.columns]
  </code></pre>
  
  <p>When I print(bd) I get this: </p>
  
  <pre><code>Empty DataFrame
  Columns: []
  Index: []
  </code></pre>
  
  <p>So I recognize that I need to add an Index but I'm not sure what it should be. The resulting file should have 6 columns, I believe, but the number of rows varies. </p>
  
  <p>I am willing to provide whatever information is necessary I'm just at a loss of what to do and would appreciate any help at all! </p>
  
  <p>Edit: Print(df.head()) yields: </p>
  
  <pre><code>print(df.head())
  Traceback (most recent call last):
  
    File "&lt;ipython-input-17-873aa293d964&gt;", line 1, in &lt;module&gt;
      print(df.head())
  
  NameError: name 'df' is not defined
  </code></pre>