Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi, I'm getting a keyerror of species, please advice after looking at this error #43

Open
ghost opened this issue Jul 24, 2020 · 1 comment

Comments

@ghost
Copy link

ghost commented Jul 24, 2020

I am using seaborn but it is just a command to count data points for each class are present
I wrote this- iris["species"].value_counts()


KeyError Traceback (most recent call last)
~/anaconda3/lib/python3.7/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: 'species'

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)
in
----> 1 iris["species"].value_counts()

~/anaconda3/lib/python3.7/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]

~/anaconda3/lib/python3.7/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: 'species'

Thank you

@praveenalbert
Copy link

Here are a few things you can check:
Column Name Existence: Ensure that there is a column named 'species' in your DataFrame. You can check the column names using iris.columns.

print(iris.columns)
Typo or Case Sensitivity: Verify that you're using the correct column name, including any capitalization. Python is case-sensitive, so 'species' is different from 'Species' or 'SPECIES'.

Data Loading: Make sure that you have successfully loaded the data into the DataFrame. If there was an issue with loading the data, the column may not exist.

Data Structure: Ensure that iris is indeed a DataFrame. You can check its type with type(iris).

Data Cleaning: It's possible that there was an issue with how the data was loaded or preprocessed. Double-check the data source or loading code to make sure the column exists.

If you're still having trouble, please provide a bit more context or the relevant code snippets so I can assist you further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant