Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
error
#1
Hello,

When I run the csv file data I have with the following command, I get an error. I wonder if I got this from a ready-made command? What should I use to avoid errors?

plt.scatter(clusters_new['isci sayisi'],clusters_new['kazana'],c=clusters_new['kume_tahmin'],cmap='rainbow')
plt.xlabel('Müşteri Çalışan Sayısı')
plt.ylabel('Müşteri Ofis Kullanım Gün Sayısı')
---------------------------------------------------------------------------
Error:
KeyError Traceback (most recent call last) File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\indexes\base.py:3621, in Index.get_loc(self, key, method, tolerance) 3620 try: -> 3621 return self._engine.get_loc(casted_key) 3622 except KeyError as err: File ~\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\_libs\index.pyx:136, in pandas._libs.index.IndexEngine.get_loc() File ~\AppData\Local\Programs\Python\Python310\lib\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: 'kazana'
The above exception was the direct cause of the following exception:

Error:
KeyError Traceback (most recent call last) Input In [83], in <cell line: 1>() ----> 1 plt.scatter(clusters_new['isci sayisi'],clusters_new['kazana'],c=clusters_new['kume_tahmin'],cmap='rainbow') 2 plt.xlabel('Müşteri Çalışan Sayısı') 3 plt.ylabel('Müşteri Ofis Kullanım Gün Sayısı') File ~\AppData\Local\Programs\Python\Python310\lib\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 ~\AppData\Local\Programs\Python\Python310\lib\site-packages\pandas\core\indexes\base.py:3623, in Index.get_loc(self, key, method, tolerance) 3621 return self._engine.get_loc(casted_key) 3622 except KeyError as err: -> 3623 raise KeyError(key) from err 3624 except TypeError: 3625 # If we have a listlike key, _check_indexing_error will raise 3626 # InvalidIndexError. Otherwise we fall through and re-raise 3627 # the TypeError. 3628 self._check_indexing_error(key) KeyError: 'kazana'
Yoriz write May-15-2022, 11:26 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
Well, KeyError: 'kazana' is quite clear: There is no key with that name.

Post your csv, or at least some lines of your csv, let's see what that looks like.

Try this, see if it works:

plt.scatter(clusters_new['isci sayisi'],c=clusters_new['kume_tahmin'],cmap='rainbow')
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020