📜  在 countplot 中规范化一个组 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:48.138000             🧑  作者: Mango

代码示例1
import numpy as np
import pandas as pd
import seaborn as sns
sns.set(color_codes=True)

df = sns.load_dataset('titanic')
df.head()

x,y = 'class', 'survived'

(df
.groupby(x)[y]
.value_counts(normalize=True)
.mul(100)
.rename('percent')
.reset_index()
.pipe((sns.catplot,'data'), x=x,y='percent',hue=y,kind='bar'))