I have following dataset
Sector Sex
A Male
C Female
B Female
B Male
A Female
A Male
C Male
C Female
B Male
B Female
Code to reproduce:
import pandas as pd
df = pd.DataFrame([
['A', Male],
['C', Female],
['B', Female],
['B', Male],
['A', Female],
['A', Male],
['C', Male],
['C', Female],
['B', Male],
['B', Female]
],
columns=['Sector', 'Sex'])
from the dataframe we can see Sector A has 2 Male and 1 Female, B has has 2 Male and 2 Female and C has 1 Male and 2 Female. What I want is make Dataframe which has Sector, Male, Female, Total Column and contains the frequency of those column like below
Sector Male Female Total
A 2 1 3
B 2 2 4
C 1 2 3
I can crosstab but I want a different dataframe with the column name I mentioned