[Python] Seaborn Catplot similar to Pandas groupby

Discussão em 'Python' iniciado por Stack, Março 6, 2025.

  1. Stack

    Stack Membro Participativo

    I am working with the Portuguese Bank Marketing dataset http://archive.ics.uci.edu/ml/datasets/Bank Marketing#

    I would like to visualise the conversion rate per some categorical feature e.g. occupation or marital status.

    Using pandas groupby() as show below

    df.groupby(["marital","y"])["y"].count().plot(kind="bar")


    I obtain the following graph [​IMG]

    However, I would like to create a more readable graph, similar to the ones in seaborn tutorials. Where X is some categorical feature, Y is some value and the Hue groups them per some other metric. [​IMG]

    My attempts so far result in the following errors:

    sns.catplot(x = df["job"].value_counts().index,
    y = df["job"].value_counts().values,
    hue="y",
    data=df,
    kind="bar")

    ValueError: Grouper and axis must be same length


    Any pointers will be appreciated!

    Continue reading...

Compartilhe esta Página