https://www.delftstack.com/ko/howto/python-pandas/how-to-count-the-frequency-a-value-occurs-in-pandas-dataframe/

df.groupby().count()메소드

import pandas as pd

df = pd.DataFrame({
                    'A': [
                        'jim',
                        'jim',
                        'jim',
                        'jim',
                        'sal',
                        'tom',
                        'tom',
                        'sal',
                        'sal'],
                    'B': [
                        'a',
                        'b', 
                        'a', 
                        'b', 
                        'b', 
                        'b', 
                        'a', 
                        'a', 
                        'b']
                    })  

freq = df.groupby(['A']).count() 
print(freq)

freq = df.groupby(['B']).count() 
print(freq)

# 출력
     B
A     
jim  4
sal  3
tom  2

   A
B   
a  4
b  5

Series.value_counts()메소드

import pandas as pd

df = pd.DataFrame({
                    'A': [
                        'jim',
                        'jim',
                        'jim',
                        'jim',
                        'sal',
                        'tom',
                        'tom',
                        'sal',
                        'sal'],
                    'B': [
                        'a',
                        'b', 
                        'a', 
                        'b', 
                        'b', 
                        'b', 
                        'a', 
                        'a', 
                        'b']
                    })  

freq = df['A'].value_counts() 
print(freq) 

freq = df['B'].value_counts() 
print(freq) 

#출력

jim    4
sal    3
tom    2
Name: A, dtype: int64
b    5
a    4
Name: B, dtype: int64

df.groupby().size()메소드

import pandas as pd

df = pd.DataFrame({
                    'A': [
                        'jim',
                        'jim',
                        'jim',
                        'jim',
                        'sal',
                        'tom',
                        'tom',
                        'sal',
                        'sal'],
                    'B': [
                        'a',
                        'b', 
                        'a', 
                        'b', 
                        'b', 
                        'b', 
                        'a', 
                        'a', 
                        'b']
                    })  

freq = df.groupby(['A', 'B']).size() 
print(freq)

# 출력

A    B
jim  a    2
     b    2
sal  a    1
     b    2
tom  a    1
     b    1
dtype: int64