1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How to plot a bar plot of 2 categorical columns using matplotlib or seaborn

Discussão em 'Python' iniciado por Stack, Setembro 15, 2025.

  1. Stack

    Stack Membro Participativo

    This might be a simple task but I am new to plotting in python and is struggling to convert logic into code. I have 2 columns like below. 0 mean not churned and 1 means churned. gender is an object column and churned is a category column

    gender|churned
    --------------
    male |0
    male |1
    female |0
    female |1
    female |1
    male |1


    I simply want a stacked bar graph (please correct me if this is not the right choice of graph) with 0 and 1 on x axis (churn column) and for each of those 2 categories I want a stacked bar graph with 2 different colours for each gender showing the total number of males and females under 0 (not churned) and total number of males and females under 1(churned).

    I tried:

    df.Churn.value_counts().plot(kind='bar')


    it gave me the total count for each 0 and 1 but i need it divided by gender aswell.

    Hope I am making sense

    Continue reading...

Compartilhe esta Página