To get the count of different classes in a pandas DataFrame column, you can use the value_counts()
function in pandas.
Here is an example code snippet:
main.py197 chars12 lines
Output:
main.py47 chars5 lines
In the above example, we create a sample pandas DataFrame with one column named "Class". We then use the value_counts()
function to count the occurrences of each class in the "Class" column, which gives us a pandas Series object with the count of each class.
You can also use normalize=True
parameter to get the frequency percentage of each class, as shown below:
main.py56 chars2 lines
Output:
main.py70 chars5 lines
This will return a pandas Series object with the frequency percentage of each class.
gistlibby LogSnag