teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

最初からコードーを書き出しました。”Sex”、”Embarked"を削除した部分はないのに、なぜか扱えない状態となってます

2020/05/05 11:51

投稿

scienceman
scienceman

スコア8

title CHANGED
File without changes
body CHANGED
@@ -67,7 +67,34 @@
67
67
  Key error
68
68
 
69
69
  ### 該当のソースコード
70
+ import pandas as pd
71
+ df = pd.read_csv("/kaggle/input/titanic/train.csv")
72
+ df.head()
73
+
74
+ df.isnull().sum()
75
+
76
+ df["Age"].fillna(df["Age"].median(),inplace=True)
77
+
78
+ df =df.drop("Cabin",axis=1)
79
+
80
+ import matplotlib.pyplot as plt
81
+ import seaborn as sns
82
+
83
+ sns.countplot(x = df["Pclass"],hue = df["Survived"])
84
+ plt.show()
85
+
86
+ import numpy as np
87
+ edge = np.arange(0,100,10)
88
+
89
+ plt.hist((df[df["Survived"]==0]["Age"],df[df["Survived"]==1]["Age"]),histtype="barstacked",bins=edge,label=[0,1])
90
+ plt.legend(title="Survived")
91
+ plt.show()
92
+
70
- ---------------------------------------------------------------------------
93
+ df["Familysize"] =df['SibSp']+df['Parch']+1
94
+
95
+ pd.crosstab(df["Familysize"],df["Survived"],normalize='index').plot(kind="bar",stacked=True)
96
+ plt.show()
97
+
71
98
  sex_dum = pd.get_dummies(df["Sex"])
72
99
  df = pd.concat((df,sex_dum),axis=1)
73
100
  df = df.drop("Sex",axis=1)