I am new to python and learning pandas myself. So I get the result for the first syntax but not for the second syntax. As per my understanding, we are using loc for label. So, we should be able to mention the column name inside the parenthesis. Could you please help me out?
df1['EdLevel'].value_counts()--this gives the results
df1.loc['EdLevel'].value_counts()---gives error while running.
The error is something like this:
KeyError Traceback (most recent call last)
~\anaconda3\lib\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\index_class_helper.pxi in pandas._libs.index.Int64Engine._check_type()
KeyError: 'EdLevel'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-105-bc8968bf3244> in <module>
----> 1 df1.loc['EdLevel'].value_counts()