Create Frequency table of column in Pandas python

Creating Frequency table of column in pandas python can be accomplished by value_counts() function.  Let’s see how to create frequency matrix or frequency table of column in pandas.

First let’s create a dataframe.

import pandas as pd
import numpy as np

data = {'Name':['James','Paul','Richards','Marico','Samantha','Ravi','Raghu','Richards','George','Ema','Samantha','Catherine'],
       'State':['Alaska','California','Texas','North Carolina','California','Texas','Alaska','Texas','North Carolina','Alaska','California','Texas']}

df1=pd.DataFrame(data, columns=['Name','State'])

print(df1)

df1 will be

Create Frequency table of column in pandas 1

 

Get frequency table of column in pandas python:

Frequency table of column in pandas for State column can be created using value_counts() as shown below.

df1.State.value_counts()

So the frequency table will be

Create Frequency table of column in pandas 2

 

p Create Frequency table of column in Pandas python                                                                                                                n Create Frequency table of column in Pandas python