Need help debugging code don't know where to start

Hello - I am trying to debug some code and wondering if anyone can help? I am running a Python script in PyCharm which basically takes a CSV file and performs some basic cleanup on a JSON. The file format hasn’t changed so the script should still work. When I run the code I get errors that I don’t know how to interpret, pasted below (removed any personal directory information and replaced with 'X’s). Anyone have any thoughts?
Traceback (most recent call last):

File “C:\Program Files\Python310\lib\site-packages\pandas\core\indexes\base.py”, line 3803, in get_loc
return self._engine.get_loc(casted_key)
File “pandas_libs\index.pyx”, line 138, in pandas._libs.index.IndexEngine.get_loc
File “pandas_libs\index.pyx”, line 165, in pandas._libs.index.IndexEngine.get_loc
File “pandas_libs\hashtable_class_helper.pxi”, line 5745, in pandas._libs.hashtable.PyObjectHashTable.get_item
File “pandas_libs\hashtable_class_helper.pxi”, line 5753, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: ‘JSON’

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “C:\Users\XXXXXXX\Documents\Work\XXXXXXXXX\XXXXXX.py”, line 73, in
for i in range(len(df[“JSON”])):
File “C:\Program Files\Python310\lib\site-packages\pandas\core\frame.py”, line 3805, in getitem
indexer = self.columns.get_loc(key)
File “C:\Program Files\Python310\lib\site-packages\pandas\core\indexes\base.py”, line 3805, in get_loc
raise KeyError(key) from err
KeyError: ‘JSON’

The traceback says:

for i in range(len(df["JSON"])):

It says it can’t find a column called “JSON”. Does the CSV file have a column with that name?

Try printing out the first line of that file. This should show what’s on that line, whatever its encoding is:

with open("path/of/CSV file", encoding="latin-1") as file:
    print(ascii(file.readline()))
1 Like

You’re awesome thank you! Initially I thought there was a more complicated issue at hand but in the end it was just a column naming issue :)!