Tuesday, November 9, 2021

Two ways to get Frequency Based Order of Categorical Data (Python)



Python Code:

import pandas as pd
from collections import Counter
df = pd.read_csv('sales_data_sample.csv')
df[['COUNTRY', 'PRODUCTLINE']] 

df[['COUNTRY']].value_counts()
list(df[['COUNTRY']].value_counts().index)
df[['PRODUCTLINE']].value_counts()
cnt_country = Counter(df['COUNTRY'])
cnt_country.most_common()
cnt_productline = Counter(df['PRODUCTLINE'])

No comments:

Post a Comment