質問編集履歴
1
最初からコードーを書き出しました。”Sex”、”Embarked"を削除した部分はないのに、なぜか扱えない状態となってます
test
CHANGED
File without changes
|
test
CHANGED
@@ -136,7 +136,61 @@
|
|
136
136
|
|
137
137
|
### 該当のソースコード
|
138
138
|
|
139
|
+
import pandas as pd
|
140
|
+
|
141
|
+
df = pd.read_csv("/kaggle/input/titanic/train.csv")
|
142
|
+
|
143
|
+
df.head()
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
df.isnull().sum()
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
df["Age"].fillna(df["Age"].median(),inplace=True)
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
df =df.drop("Cabin",axis=1)
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
import matplotlib.pyplot as plt
|
160
|
+
|
161
|
+
import seaborn as sns
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
sns.countplot(x = df["Pclass"],hue = df["Survived"])
|
166
|
+
|
167
|
+
plt.show()
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
import numpy as np
|
172
|
+
|
173
|
+
edge = np.arange(0,100,10)
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
plt.hist((df[df["Survived"]==0]["Age"],df[df["Survived"]==1]["Age"]),histtype="barstacked",bins=edge,label=[0,1])
|
178
|
+
|
179
|
+
plt.legend(title="Survived")
|
180
|
+
|
181
|
+
plt.show()
|
182
|
+
|
183
|
+
|
184
|
+
|
139
|
-
|
185
|
+
df["Familysize"] =df['SibSp']+df['Parch']+1
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
pd.crosstab(df["Familysize"],df["Survived"],normalize='index').plot(kind="bar",stacked=True)
|
190
|
+
|
191
|
+
plt.show()
|
192
|
+
|
193
|
+
|
140
194
|
|
141
195
|
sex_dum = pd.get_dummies(df["Sex"])
|
142
196
|
|