我正在嘗試使用從單個資料集(
Asns.catplot()使用新列col=可能如下所示:
sns.set()
g = sns.catplot(data=df, x='Sex', col='Category', sharey=True, height=4, aspect=0.5, palette='rocket', kind='count')
g.set(xlabel='')
plt.tight_layout()
plt.show()

uj5u.com熱心網友回復:
您應該將生成的資料幀放在一個串列中,并使用for回圈逐個迭代它們。將相關代碼放在一個函式中也可以幫助您不重復自己。
def plot_counts(dataframe):
dataframe['Sex'].value_counts()
sns.countplot(data=dataframe, x='Sex')
df = pd.read_csv("heart.csv")
plot_counts(df)
Clv = df.loc[0:302, :]
Hng = df.loc[303:(303 293), :]
Swtz = df.loc[(303 294):(303 294 122), :]
Lb = df.loc[(303 294 123):(303 294 123 199), :]
Stl = df.loc[(303 294 123 200):, :]
df_list = [Clv, Hng, Swtz, Lb, Stl]
for dataframe in df_list:
plot_counts(dataframe)
如果只需要做'Sex'一次列,可以去掉函式定義,直接呼叫sns.countplot():
df = pd.read_csv("heart.csv")
df['Sex'].value_counts()
sns.countplot(data=df, x='Sex')
Clv = df.loc[0:302, :]
Hng = df.loc[303:(303 293), :]
Swtz = df.loc[(303 294):(303 294 122), :]
Lb = df.loc[(303 294 123):(303 294 123 199), :]
Stl = df.loc[(303 294 123 200):, :]
df_list = [Clv, Hng, Swtz, Lb, Stl]
for dataframe in df_list:
sns.countplot(data=dataframe, x='Sex')
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/412598.html
標籤:
