Challenge: Clean a string problem strange error code

laptops["weight"] = laptops["weight"].str.replace('kgs','')
laptops["weight"] = laptops["weight"].str.replace('kg','')
laptops["weight"] = laptops["weight"].astype(float)

laptops.rename({"weight":"weight_kg"}, axis = 1, inplace = True)


laptops.to_csv('laptops_cleaned.csv', index = False)

What I expected to happen:
No errors. Challenge code completed correctly.

What actually happened:
An error that I have no idea how to debug. Even when I copy/paste dq’s solution, I’m getting this error.

Replace this line with the output/error

KeyError Traceback (most recent call last)
/dataquest/system/env/python3/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2645 try:
→ 2646 return self._engine.get_loc(key)
2647 except KeyError:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: ‘screen_size’

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)
in
11 laptops.columns = [clean_col(c) for c in laptops.columns]
12
—> 13 laptops[“screen_size”] = laptops[“screen_size”].str.replace(’"’,’’).astype(float)
14 laptops.rename({“screen_size”: “screen_size_inches”}, axis=1, inplace=True)
15 laptops[“ram”] = laptops[“ram”].str.replace(‘GB’,’’).astype(float)

/dataquest/system/env/python3/lib/python3.8/site-packages/pandas/core/frame.py in getitem(self, key)
2798 if self.columns.nlevels > 1:
2799 return self._getitem_multilevel(key)
→ 2800 indexer = self.columns.get_loc(key)
2801 if is_integer(indexer):
2802 indexer = [indexer]

/dataquest/system/env/python3/lib/python3.8/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2646 return self._engine.get_loc(key)
2647 except KeyError:
→ 2648 return self._engine.get_loc(self._maybe_cast_indexer(key))
2649 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
2650 if indexer.ndim > 1 or indexer.size > 1:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: ‘screen_size’

Also, I’m using DQ’s online coding screen.

That’s weird, the error says its not finding a column name that has nothing to do with your input code. The code is looking for ‘screen_size’ and in the error they go through renaming ‘screen_size’ to ‘screen_size_inches’.

I went and tested the lesson and the provided answer ran fine for me. Unsure what’s going on here.

It worked out! I think my computer was just on overdrive from all the computing I was doing that day and maybe got backed up? I reran my code (which was a little different from the answer key) and submitted. On to the project! Thank you!!!