[Python] Seaborn histogram to plot survey answer frequency by gender

Discussão em 'Python' iniciado por Stack, Julho 10, 2025.

  1. Stack

    Stack Membro Participativo

    I have some survey question answers (letters A, B, C) I'd like to plot in a Seaborn histogram, with the frequency of each response letter grouped by gender.

    import pandas as pd
    answers = ['A', 'B', 'A', 'B', 'A', 'A', 'B', 'B', 'B', 'A', 'C', 'B', 'A', 'C']
    genders = ['M', 'M', 'F', 'M', 'F', 'M', 'F', 'M', 'M', 'F', 'M', 'M', 'F', 'M']
    df = pd.DataFrame({'Answer': answers, 'Gender': genders})


    I'd like the output to resemble either clustered columns:

    [​IMG]

    or stacked columns:

    [​IMG]

    Seaborn isn't mandatory - it's just what I've been trying for a while. I've been struggling for days since categorical data like mine isn't easy to find in online examples.

    Any help is tremendously appreciated.

    Continue reading...

Compartilhe esta Página