'KeyError: "None of [Index(['Patient number',] python

#import excel 
path = '/content/drive/MyDrive/data/dataset MS.xlsx'
df=pd.read_excel(path)
X=df[['Patient number','Gender','Age (years)','Other']].values
Y=df['Pationt'].values
model.fit(X,Y)
y_pred=model.pridict(X)

when i run the code i have error:

KeyError Traceback (most recent call last) in () 2 path = '/content/drive/MyDrive/Graduation_Project_I/data/dataset MS.xlsx' 3 df=pd.read_excel(path) ----> 4 X=df[['Patient number','Gender','Age (years)', 'Other']].values 5 Y=df['Pationt'].values 6 model.fit(X,Y)

2 frames /usr/local/lib/python3.7/dist-packages/pandas/core/indexing.py in _validate_read_indexer(self, key, indexer, axis) 1372 if use_interval_msg: 1373 key = list(key) -> 1374 raise KeyError(f"None of [{key}] are in the [{axis_name}]") 1375 1376 not_found = list(ensure_index(key)[missing_mask.nonzero()[0]].unique())

KeyError: "None of [Index(['Patient number', 'Gender', 'Age (years)', 'Other'], dtype='object')] are in the [columns]"

what should i do?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source