df1 = df.groupby(['doctor name', 'gender']).size().unstack(level=0,
    fill_value=0)
print(df1)
In pandas, how to perform value counts of gender(or any categorical variable) based on another categorical column?