问题描述 投票:0回答:1
使用pandas groupby()如下显示
df.groupby(["marital","y"])["y"].count().plot(kind="bar")

I获得以下图

,但是,我想创建一个更可读的图,类似于Seaborn教程中的图。 其中x是某些分类特征,y是某些值,而色相将它们分组为其他一些度量。


到目前为止,我的尝试导致以下错误:

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 enter image description here 任何指针都将不胜感激!

是您想要的:enter image description here df = sns.load_dataset('titanic') df.groupby(['sex', 'class']).size().unstack().plot.bar() # also # pd.crosstab(df['sex'], df['class']).plot.bar()

输出:

python pandas seaborn catplot
1个回答
1
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.