df.groupby(["marital","y"])["y"].count().plot(kind="bar")
,但是,我想创建一个更可读的图,类似于Seaborn教程中的图。 其中x是某些分类特征,y是某些值,而色相将它们分组为其他一些度量。 到目前为止,我的尝试导致以下错误:
是您想要的:
df = sns.load_dataset('titanic')
df.groupby(['sex', 'class']).size().unstack().plot.bar()
# also
# pd.crosstab(df['sex'], df['class']).plot.bar()
输出: