The CSV file I am importing has a column named 'MED EXP DATE'. I reference this same column earlier in the code with no problem. When I reference it later, I get a key error.
import pandas as pd
df = pd.read_csv(r"C:\Users\Desktop\Air_Rally_Marketing\PILOT_BASIC.csv", low_memory=False, dtype={'UNIQUE ID': str, 'FIRST NAME': str,'LAST NAME': str, 'STREET 1': str, 'STREET 2': str, 'CITY': str, 'STATE': str, 'ZIP CODE': str, 'MED DATE': str, 'MED EXP DATE': str})
df.dropna(inplace = True)
df['EXP DATE LEN'] = df['MED EXP DATE'].apply(len) #creates a column to store the length of the column MED EXP DATE
print(df.head)
This is the error I receive:
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 135, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index_class_helper.pxi", line 109, in pandas._libs.index.Int64Engine._check_type
KeyError: 'MED EXP DATE'
When I search the meaning of this error, my understanding is that it means I am referencing a key that cannot be found. I'm confused by this because I reference "MED EXP DATE" in a prior line and do not get the key error there.