Dec-03-2021, 06:38 AM
Hello everyone,
I'm just learning Python for the first time and am going through the tutorial on Learnpython.org. I'm getting this weird error. I don't think I'm writing anything wrong. I'm guessing this is a bug in my version of Python? Should I downgrade to another version?
I'm using Visual Studio Code.
Not sure if this matters, but I do have Mingw64 installed as well.
I'm just learning Python for the first time and am going through the tutorial on Learnpython.org. I'm getting this weird error. I don't think I'm writing anything wrong. I'm guessing this is a bug in my version of Python? Should I downgrade to another version?
1 2 3 4 5 6 |
import pandas as pd # cars = {'cars_per_cap': [809, 731, 588, 18, 200, 70, 45], 'country': ['United States', 'Australia', 'Japan', 'India', 'Russia', 'Morocco', 'Egypt'], 'drives_right': ['true', 'false', 'false', 'false', 'true', 'true', 'true']} cars = pd.read_csv( 'cars.csv' ) print (cars[ 'country' ]) |
Error:Traceback (most recent call last):
File "C:\Users\kaega\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\indexes\base.py", line 3361, in get_loc
return self._engine.get_loc(casted_key)
File "pandas\_libs\index.pyx", line 76, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 5198, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 5206, in pandas._libs.hashtable.PyObjectHashTable.get_item
Traceback (most recent call last):
File "c:\Users\kaega\Documents\Programming\Python Learning Environment\script.py", line 6, in <module>
print(cars['country'])
File "C:\Users\kaega\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\frame.py", line 3458, in __getitem__
indexer = self.columns.get_loc(key)
File "C:\Users\kaega\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\indexes\base.py", line 3363, in get_loc
raise KeyError(key) from err
KeyError: 'country'
I'm using Python 3.10.0 downloaded from Python.org. I'm using Visual Studio Code.
Not sure if this matters, but I do have Mingw64 installed as well.