如何根据情况创建分组条形图
How to create grouped bar chart for situations
我正在尝试创建分组条形图。在这个图表中,我想根据他们的登船点(C,Q,S)来比较他们是幸存还是死亡。在这段代码中,我无法决定 y 是什么。
df_drop_Emb = df_titanic.dropna(subset= ["Embarked"])
plt.figure(figsize=(10, 8))
sns.barplot(x="Embarked",
y="Survived",
hue="Survived",
data=df_drop_Emb)
plt.ylabel("number of people", size=14)
plt.xlabel("ports", size=14)
plt.title(" the number of passengers who survived for each port", size=18)
可能需要先groupby统计幸存者一栏的lived/died
import pandas as pd
import seaborn as sns
df = pd.read_csv('train.csv')
df = df.groupby(['Embarked', 'Survived']).size().reset_index(name='count')
sns.barplot(data=df, x='Embarked',y='count',hue='Survived')
我正在尝试创建分组条形图。在这个图表中,我想根据他们的登船点(C,Q,S)来比较他们是幸存还是死亡。在这段代码中,我无法决定 y 是什么。
df_drop_Emb = df_titanic.dropna(subset= ["Embarked"])
plt.figure(figsize=(10, 8))
sns.barplot(x="Embarked",
y="Survived",
hue="Survived",
data=df_drop_Emb)
plt.ylabel("number of people", size=14)
plt.xlabel("ports", size=14)
plt.title(" the number of passengers who survived for each port", size=18)
可能需要先groupby统计幸存者一栏的lived/died
import pandas as pd
import seaborn as sns
df = pd.read_csv('train.csv')
df = df.groupby(['Embarked', 'Survived']).size().reset_index(name='count')
sns.barplot(data=df, x='Embarked',y='count',hue='Survived')