Ankita Prasad
Ankita Prasad

Reputation: 47

KeyError: "None of [Index(['file_path'], dtype='object')] are in the [columns]

I tried to run this file and it's giving me the following error while trying to call the function. I couldn't understand what is causing this error. I want to do some image enhancement so that my model can better understand them while training. Any other suggestions or codes to do the same are welcome.

Traceback (most recent call last):
  File "C:/DIP_Ankita/image_corrector.py", line 12, in <module>
    data = data[['file_path']]
  File "C:\Users\srchirag27\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\frame.py", line 3001, in __getitem__
    indexer = self.loc._convert_to_indexer(key, axis=1, raise_missing=True)
  File "C:\Users\srchirag27\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\indexing.py", line 1285, in _convert_to_indexer
    return self._get_listlike_indexer(obj, axis, **kwargs)[1]
  File "C:\Users\srchirag27\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\indexing.py", line 1092, in _get_listlike_indexer
    keyarr, indexer, o._get_axis_number(axis), raise_missing=raise_missing
  File "C:\Users\srchirag27\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\indexing.py", line 1177, in _validate_read_indexer
    key=key, axis=self.obj._get_axis_name(axis)
KeyError: "None of [Index(['file_path'], dtype='object')] are in the [columns]"

Upvotes: 1

Views: 620

Answers (3)

Ankita Prasad
Ankita Prasad

Reputation: 47

There was some issue with the file being saved. The previously written code was being called rather than the updated one. I deleted the file and then created another one with the same script and it worked fine.

Upvotes: 1

Marcelo
Marcelo

Reputation: 87

I think you are missing np before conj, np.conj() in your line 10

Upvotes: 0

Maitreya Verma
Maitreya Verma

Reputation: 661

data[['file_path']] creates a new dataframe containing only one column - file_path.

Check data.columns and if the required column is not there then you need to ensure that column is being passed.

Upvotes: 0

Related Questions