I have a data set with two columns called sale price and property taxes and i want to perform linear regression on them I have imported numpy and pandas and I call my csv file:
data=pd.read_csv('HW2.csv')
data.shape
data.info()
data.describe()
This is what is displayed
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10 entries, 0 to 9
Data columns (total 2 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Sale Price 10 non-null float64
1 Property Taxes 10 non-null float64
dtypes: float64(2)
memory usage: 288.0 bytes
Sale Price Property Taxes
count 10.000000 10.000000
mean 35.810000 6.896000
std 6.598392 1.673952
min 25.900000 4.920000
25% 30.150000 5.270000
50% 37.400000 6.810000
75% 38.650000 8.305000
max 45.800000 9.140000
Finally to draw my scatter plot I run this
h=data["Sale Price"]
w=data["Property Taxes"]
plt.scatter(h, w)
plt.show()
Only to get the following error:
KeyError Traceback (most recent call last)
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/core/indexes/base.py:3629, in Index.get_loc(self, key, method, tolerance)
3628 try:
-> 3629 return self._engine.get_loc(casted_key)
3630 except KeyError as err:
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/_libs/index.pyx:136, in pandas._libs.index.IndexEngine.get_loc()
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/_libs/index.pyx:163, in pandas._libs.index.IndexEngine.get_loc()
File pandas/_libs/hashtable_class_helper.pxi:5198, in pandas._libs.hashtable.PyObjectHashTable.get_item()
File pandas/_libs/hashtable_class_helper.pxi:5206, in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'Property Taxes'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
Input In [41], in <cell line: 2>()
1 h=data["Sale Price"]
----> 2 w=data["Property Taxes"]
3 plt.scatter(h, w)
4 plt.show()
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/core/frame.py:3505, in DataFrame.__getitem__(self, key)
3503 if self.columns.nlevels > 1:
3504 return self._getitem_multilevel(key)
-> 3505 indexer = self.columns.get_loc(key)
3506 if is_integer(indexer):
3507 indexer = [indexer]
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/core/indexes/base.py:3631, in Index.get_loc(self, key, method, tolerance)
3629 return self._engine.get_loc(casted_key)
3630 except KeyError as err:
-> 3631 raise KeyError(key) from err
3632 except TypeError:
3633 # If we have a listlike key, _check_indexing_error will raise
3634 # InvalidIndexError. Otherwise we fall through and re-raise
3635 # the TypeError.
3636 self._check_indexing_error(key)
KeyError: 'Property Taxes'
What am I doing wrong?