Creating dummy variables in pandas
This introduction to pandas is derived from Data School's pandas Q&A with my own notes and code.
Creating dummy variables¶
In [1]:
import pandas as pd
In [2]:
url = 'http://bit.ly/kaggletrain'
train = pd.read_csv(url)
In [3]:
train.head()
Out[3]:
PassengerId | Survived | Pclass | Name | Sex | Age | SibSp | Parch | Ticket | Fare | Cabin | Embarked | |
---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 0 | 3 | Braund, Mr. Owen Harris | male | 22.0 | 1 | 0 | A/5 21171 | 7.2500 | NaN | S |
1 | 2 | 1 | 1 | Cumings, Mrs. John Bradley (Florence Briggs Th... | female | 38.0 | 1 | 0 | PC 17599 | 71.2833 | C85 | C |
2 | 3 | 1 | 3 | Heikkinen, Miss. Laina | female | 26.0 | 0 | 0 | STON/O2. 3101282 | 7.9250 | NaN | S |
3 | 4 | 1 | 1 | Futrelle, Mrs. Jacques Heath (Lily May Peel) | female | 35.0 | 1 | 0 | 113803 | 53.1000 | C123 | S |
4 | 5 | 0 | 3 | Allen, Mr. William Henry | male | 35.0 | 0 | 0 | 373450 | 8.0500 | NaN | S |
In [9]:
# using .map to create dummy variables
# train['category_name'] = train.Category.map({'unique_term':0, 'unique_term2':1})
train['Sex_male'] = train.Sex.map({'female':0, 'male':1})
In [5]:
train.head()
Out[5]:
PassengerId | Survived | Pclass | Name | Sex | Age | SibSp | Parch | Ticket | Fare | Cabin | Embarked | Sex_male | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 0 | 3 | Braund, Mr. Owen Harris | male | 22.0 | 1 | 0 | A/5 21171 | 7.2500 | NaN | S | 1 |
1 | 2 | 1 | 1 | Cumings, Mrs. John Bradley (Florence Briggs Th... | female | 38.0 | 1 | 0 | PC 17599 | 71.2833 | C85 | C | 0 |
2 | 3 | 1 | 3 | Heikkinen, Miss. Laina | female | 26.0 | 0 | 0 | STON/O2. 3101282 | 7.9250 | NaN | S | 0 |
3 | 4 | 1 | 1 | Futrelle, Mrs. Jacques Heath (Lily May Peel) | female | 35.0 | 1 | 0 | 113803 | 53.1000 | C123 | S | 0 |
4 | 5 | 0 | 3 | Allen, Mr. William Henry | male | 35.0 | 0 | 0 | 373450 | 8.0500 | NaN | S | 1 |
Alternative method for creating dummy variables
In [10]:
pd.get_dummies(train.Sex)
Out[10]:
female | male | |
---|---|---|
0 | 0.0 | 1.0 |
1 | 1.0 | 0.0 |
2 | 1.0 | 0.0 |
3 | 1.0 | 0.0 |
4 | 0.0 | 1.0 |
5 | 0.0 | 1.0 |
6 | 0.0 | 1.0 |
7 | 0.0 | 1.0 |
8 | 1.0 | 0.0 |
9 | 1.0 | 0.0 |
10 | 1.0 | 0.0 |
11 | 1.0 | 0.0 |
12 | 0.0 | 1.0 |
13 | 0.0 | 1.0 |
14 | 1.0 | 0.0 |
15 | 1.0 | 0.0 |
16 | 0.0 | 1.0 |
17 | 0.0 | 1.0 |
18 | 1.0 | 0.0 |
19 | 1.0 | 0.0 |
20 | 0.0 | 1.0 |
21 | 0.0 | 1.0 |
22 | 1.0 | 0.0 |
23 | 0.0 | 1.0 |
24 | 1.0 | 0.0 |
25 | 1.0 | 0.0 |
26 | 0.0 | 1.0 |
27 | 0.0 | 1.0 |
28 | 1.0 | 0.0 |
29 | 0.0 | 1.0 |
... | ... | ... |
861 | 0.0 | 1.0 |
862 | 1.0 | 0.0 |
863 | 1.0 | 0.0 |
864 | 0.0 | 1.0 |
865 | 1.0 | 0.0 |
866 | 1.0 | 0.0 |
867 | 0.0 | 1.0 |
868 | 0.0 | 1.0 |
869 | 0.0 | 1.0 |
870 | 0.0 | 1.0 |
871 | 1.0 | 0.0 |
872 | 0.0 | 1.0 |
873 | 0.0 | 1.0 |
874 | 1.0 | 0.0 |
875 | 1.0 | 0.0 |
876 | 0.0 | 1.0 |
877 | 0.0 | 1.0 |
878 | 0.0 | 1.0 |
879 | 1.0 | 0.0 |
880 | 1.0 | 0.0 |
881 | 0.0 | 1.0 |
882 | 1.0 | 0.0 |
883 | 0.0 | 1.0 |
884 | 0.0 | 1.0 |
885 | 1.0 | 0.0 |
886 | 0.0 | 1.0 |
887 | 1.0 | 0.0 |
888 | 1.0 | 0.0 |
889 | 0.0 | 1.0 |
890 | 0.0 | 1.0 |
891 rows × 2 columns
If you have k unique terms, you use k - 1 dummy variables to represent
In [33]:
# iloc works on positions (integers)
# this iloc code would always work for any number and name of categories
pd.get_dummies(train.Sex, prefix='Sex').iloc[:, 1:]
# alternative using loc that works on labels
# this method has to be modified for each dataset
pd.get_dummies(train.Sex, prefix='Sex').loc[:, 'Sex_male':]
Out[33]:
Sex_male | |
---|---|
0 | 1.0 |
1 | 0.0 |
2 | 0.0 |
3 | 0.0 |
4 | 1.0 |
5 | 1.0 |
6 | 1.0 |
7 | 1.0 |
8 | 0.0 |
9 | 0.0 |
10 | 0.0 |
11 | 0.0 |
12 | 1.0 |
13 | 1.0 |
14 | 0.0 |
15 | 0.0 |
16 | 1.0 |
17 | 1.0 |
18 | 0.0 |
19 | 0.0 |
20 | 1.0 |
21 | 1.0 |
22 | 0.0 |
23 | 1.0 |
24 | 0.0 |
25 | 0.0 |
26 | 1.0 |
27 | 1.0 |
28 | 0.0 |
29 | 1.0 |
... | ... |
861 | 1.0 |
862 | 0.0 |
863 | 0.0 |
864 | 1.0 |
865 | 0.0 |
866 | 0.0 |
867 | 1.0 |
868 | 1.0 |
869 | 1.0 |
870 | 1.0 |
871 | 0.0 |
872 | 1.0 |
873 | 1.0 |
874 | 0.0 |
875 | 0.0 |
876 | 1.0 |
877 | 1.0 |
878 | 1.0 |
879 | 0.0 |
880 | 0.0 |
881 | 1.0 |
882 | 0.0 |
883 | 1.0 |
884 | 1.0 |
885 | 0.0 |
886 | 1.0 |
887 | 0.0 |
888 | 0.0 |
889 | 1.0 |
890 | 1.0 |
891 rows × 1 columns
In [29]:
train.Embarked.value_counts()
Out[29]:
S 644 C 168 Q 77 Name: Embarked, dtype: int64
As we can see here, there are 3 unique terms
In [31]:
# we only need k - 1, hence 2 dummy variables here
pd.get_dummies(train.Embarked, prefix='Embarked').iloc[:, 1:]
Out[31]:
Embarked_Q | Embarked_S | |
---|---|---|
0 | 0.0 | 1.0 |
1 | 0.0 | 0.0 |
2 | 0.0 | 1.0 |
3 | 0.0 | 1.0 |
4 | 0.0 | 1.0 |
5 | 1.0 | 0.0 |
6 | 0.0 | 1.0 |
7 | 0.0 | 1.0 |
8 | 0.0 | 1.0 |
9 | 0.0 | 0.0 |
10 | 0.0 | 1.0 |
11 | 0.0 | 1.0 |
12 | 0.0 | 1.0 |
13 | 0.0 | 1.0 |
14 | 0.0 | 1.0 |
15 | 0.0 | 1.0 |
16 | 1.0 | 0.0 |
17 | 0.0 | 1.0 |
18 | 0.0 | 1.0 |
19 | 0.0 | 0.0 |
20 | 0.0 | 1.0 |
21 | 0.0 | 1.0 |
22 | 1.0 | 0.0 |
23 | 0.0 | 1.0 |
24 | 0.0 | 1.0 |
25 | 0.0 | 1.0 |
26 | 0.0 | 0.0 |
27 | 0.0 | 1.0 |
28 | 1.0 | 0.0 |
29 | 0.0 | 1.0 |
... | ... | ... |
861 | 0.0 | 1.0 |
862 | 0.0 | 1.0 |
863 | 0.0 | 1.0 |
864 | 0.0 | 1.0 |
865 | 0.0 | 1.0 |
866 | 0.0 | 0.0 |
867 | 0.0 | 1.0 |
868 | 0.0 | 1.0 |
869 | 0.0 | 1.0 |
870 | 0.0 | 1.0 |
871 | 0.0 | 1.0 |
872 | 0.0 | 1.0 |
873 | 0.0 | 1.0 |
874 | 0.0 | 0.0 |
875 | 0.0 | 0.0 |
876 | 0.0 | 1.0 |
877 | 0.0 | 1.0 |
878 | 0.0 | 1.0 |
879 | 0.0 | 0.0 |
880 | 0.0 | 1.0 |
881 | 0.0 | 1.0 |
882 | 0.0 | 1.0 |
883 | 0.0 | 1.0 |
884 | 0.0 | 1.0 |
885 | 1.0 | 0.0 |
886 | 0.0 | 1.0 |
887 | 0.0 | 1.0 |
888 | 0.0 | 1.0 |
889 | 0.0 | 0.0 |
890 | 1.0 | 0.0 |
891 rows × 2 columns
In [34]:
embarked_dummies = pd.get_dummies(train.Embarked, prefix='Embarked').iloc[:, 1:]
In [35]:
# concatenate columns
# axis=1
pd.concat([train, embarked_dummies], axis=1)
Out[35]:
PassengerId | Survived | Pclass | Name | Sex | Age | SibSp | Parch | Ticket | Fare | Cabin | Embarked | Sex_male | Embarked_Q | Embarked_S | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 0 | 3 | Braund, Mr. Owen Harris | male | 22.0 | 1 | 0 | A/5 21171 | 7.2500 | NaN | S | 1 | 0.0 | 1.0 |
1 | 2 | 1 | 1 | Cumings, Mrs. John Bradley (Florence Briggs Th... | female | 38.0 | 1 | 0 | PC 17599 | 71.2833 | C85 | C | 0 | 0.0 | 0.0 |
2 | 3 | 1 | 3 | Heikkinen, Miss. Laina | female | 26.0 | 0 | 0 | STON/O2. 3101282 | 7.9250 | NaN | S | 0 | 0.0 | 1.0 |
3 | 4 | 1 | 1 | Futrelle, Mrs. Jacques Heath (Lily May Peel) | female | 35.0 | 1 | 0 | 113803 | 53.1000 | C123 | S | 0 | 0.0 | 1.0 |
4 | 5 | 0 | 3 | Allen, Mr. William Henry | male | 35.0 | 0 | 0 | 373450 | 8.0500 | NaN | S | 1 | 0.0 | 1.0 |
5 | 6 | 0 | 3 | Moran, Mr. James | male | NaN | 0 | 0 | 330877 | 8.4583 | NaN | Q | 1 | 1.0 | 0.0 |
6 | 7 | 0 | 1 | McCarthy, Mr. Timothy J | male | 54.0 | 0 | 0 | 17463 | 51.8625 | E46 | S | 1 | 0.0 | 1.0 |
7 | 8 | 0 | 3 | Palsson, Master. Gosta Leonard | male | 2.0 | 3 | 1 | 349909 | 21.0750 | NaN | S | 1 | 0.0 | 1.0 |
8 | 9 | 1 | 3 | Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg) | female | 27.0 | 0 | 2 | 347742 | 11.1333 | NaN | S | 0 | 0.0 | 1.0 |
9 | 10 | 1 | 2 | Nasser, Mrs. Nicholas (Adele Achem) | female | 14.0 | 1 | 0 | 237736 | 30.0708 | NaN | C | 0 | 0.0 | 0.0 |
10 | 11 | 1 | 3 | Sandstrom, Miss. Marguerite Rut | female | 4.0 | 1 | 1 | PP 9549 | 16.7000 | G6 | S | 0 | 0.0 | 1.0 |
11 | 12 | 1 | 1 | Bonnell, Miss. Elizabeth | female | 58.0 | 0 | 0 | 113783 | 26.5500 | C103 | S | 0 | 0.0 | 1.0 |
12 | 13 | 0 | 3 | Saundercock, Mr. William Henry | male | 20.0 | 0 | 0 | A/5. 2151 | 8.0500 | NaN | S | 1 | 0.0 | 1.0 |
13 | 14 | 0 | 3 | Andersson, Mr. Anders Johan | male | 39.0 | 1 | 5 | 347082 | 31.2750 | NaN | S | 1 | 0.0 | 1.0 |
14 | 15 | 0 | 3 | Vestrom, Miss. Hulda Amanda Adolfina | female | 14.0 | 0 | 0 | 350406 | 7.8542 | NaN | S | 0 | 0.0 | 1.0 |
15 | 16 | 1 | 2 | Hewlett, Mrs. (Mary D Kingcome) | female | 55.0 | 0 | 0 | 248706 | 16.0000 | NaN | S | 0 | 0.0 | 1.0 |
16 | 17 | 0 | 3 | Rice, Master. Eugene | male | 2.0 | 4 | 1 | 382652 | 29.1250 | NaN | Q | 1 | 1.0 | 0.0 |
17 | 18 | 1 | 2 | Williams, Mr. Charles Eugene | male | NaN | 0 | 0 | 244373 | 13.0000 | NaN | S | 1 | 0.0 | 1.0 |
18 | 19 | 0 | 3 | Vander Planke, Mrs. Julius (Emelia Maria Vande... | female | 31.0 | 1 | 0 | 345763 | 18.0000 | NaN | S | 0 | 0.0 | 1.0 |
19 | 20 | 1 | 3 | Masselmani, Mrs. Fatima | female | NaN | 0 | 0 | 2649 | 7.2250 | NaN | C | 0 | 0.0 | 0.0 |
20 | 21 | 0 | 2 | Fynney, Mr. Joseph J | male | 35.0 | 0 | 0 | 239865 | 26.0000 | NaN | S | 1 | 0.0 | 1.0 |
21 | 22 | 1 | 2 | Beesley, Mr. Lawrence | male | 34.0 | 0 | 0 | 248698 | 13.0000 | D56 | S | 1 | 0.0 | 1.0 |
22 | 23 | 1 | 3 | McGowan, Miss. Anna "Annie" | female | 15.0 | 0 | 0 | 330923 | 8.0292 | NaN | Q | 0 | 1.0 | 0.0 |
23 | 24 | 1 | 1 | Sloper, Mr. William Thompson | male | 28.0 | 0 | 0 | 113788 | 35.5000 | A6 | S | 1 | 0.0 | 1.0 |
24 | 25 | 0 | 3 | Palsson, Miss. Torborg Danira | female | 8.0 | 3 | 1 | 349909 | 21.0750 | NaN | S | 0 | 0.0 | 1.0 |
25 | 26 | 1 | 3 | Asplund, Mrs. Carl Oscar (Selma Augusta Emilia... | female | 38.0 | 1 | 5 | 347077 | 31.3875 | NaN | S | 0 | 0.0 | 1.0 |
26 | 27 | 0 | 3 | Emir, Mr. Farred Chehab | male | NaN | 0 | 0 | 2631 | 7.2250 | NaN | C | 1 | 0.0 | 0.0 |
27 | 28 | 0 | 1 | Fortune, Mr. Charles Alexander | male | 19.0 | 3 | 2 | 19950 | 263.0000 | C23 C25 C27 | S | 1 | 0.0 | 1.0 |
28 | 29 | 1 | 3 | O'Dwyer, Miss. Ellen "Nellie" | female | NaN | 0 | 0 | 330959 | 7.8792 | NaN | Q | 0 | 1.0 | 0.0 |
29 | 30 | 0 | 3 | Todoroff, Mr. Lalio | male | NaN | 0 | 0 | 349216 | 7.8958 | NaN | S | 1 | 0.0 | 1.0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
861 | 862 | 0 | 2 | Giles, Mr. Frederick Edward | male | 21.0 | 1 | 0 | 28134 | 11.5000 | NaN | S | 1 | 0.0 | 1.0 |
862 | 863 | 1 | 1 | Swift, Mrs. Frederick Joel (Margaret Welles Ba... | female | 48.0 | 0 | 0 | 17466 | 25.9292 | D17 | S | 0 | 0.0 | 1.0 |
863 | 864 | 0 | 3 | Sage, Miss. Dorothy Edith "Dolly" | female | NaN | 8 | 2 | CA. 2343 | 69.5500 | NaN | S | 0 | 0.0 | 1.0 |
864 | 865 | 0 | 2 | Gill, Mr. John William | male | 24.0 | 0 | 0 | 233866 | 13.0000 | NaN | S | 1 | 0.0 | 1.0 |
865 | 866 | 1 | 2 | Bystrom, Mrs. (Karolina) | female | 42.0 | 0 | 0 | 236852 | 13.0000 | NaN | S | 0 | 0.0 | 1.0 |
866 | 867 | 1 | 2 | Duran y More, Miss. Asuncion | female | 27.0 | 1 | 0 | SC/PARIS 2149 | 13.8583 | NaN | C | 0 | 0.0 | 0.0 |
867 | 868 | 0 | 1 | Roebling, Mr. Washington Augustus II | male | 31.0 | 0 | 0 | PC 17590 | 50.4958 | A24 | S | 1 | 0.0 | 1.0 |
868 | 869 | 0 | 3 | van Melkebeke, Mr. Philemon | male | NaN | 0 | 0 | 345777 | 9.5000 | NaN | S | 1 | 0.0 | 1.0 |
869 | 870 | 1 | 3 | Johnson, Master. Harold Theodor | male | 4.0 | 1 | 1 | 347742 | 11.1333 | NaN | S | 1 | 0.0 | 1.0 |
870 | 871 | 0 | 3 | Balkic, Mr. Cerin | male | 26.0 | 0 | 0 | 349248 | 7.8958 | NaN | S | 1 | 0.0 | 1.0 |
871 | 872 | 1 | 1 | Beckwith, Mrs. Richard Leonard (Sallie Monypeny) | female | 47.0 | 1 | 1 | 11751 | 52.5542 | D35 | S | 0 | 0.0 | 1.0 |
872 | 873 | 0 | 1 | Carlsson, Mr. Frans Olof | male | 33.0 | 0 | 0 | 695 | 5.0000 | B51 B53 B55 | S | 1 | 0.0 | 1.0 |
873 | 874 | 0 | 3 | Vander Cruyssen, Mr. Victor | male | 47.0 | 0 | 0 | 345765 | 9.0000 | NaN | S | 1 | 0.0 | 1.0 |
874 | 875 | 1 | 2 | Abelson, Mrs. Samuel (Hannah Wizosky) | female | 28.0 | 1 | 0 | P/PP 3381 | 24.0000 | NaN | C | 0 | 0.0 | 0.0 |
875 | 876 | 1 | 3 | Najib, Miss. Adele Kiamie "Jane" | female | 15.0 | 0 | 0 | 2667 | 7.2250 | NaN | C | 0 | 0.0 | 0.0 |
876 | 877 | 0 | 3 | Gustafsson, Mr. Alfred Ossian | male | 20.0 | 0 | 0 | 7534 | 9.8458 | NaN | S | 1 | 0.0 | 1.0 |
877 | 878 | 0 | 3 | Petroff, Mr. Nedelio | male | 19.0 | 0 | 0 | 349212 | 7.8958 | NaN | S | 1 | 0.0 | 1.0 |
878 | 879 | 0 | 3 | Laleff, Mr. Kristo | male | NaN | 0 | 0 | 349217 | 7.8958 | NaN | S | 1 | 0.0 | 1.0 |
879 | 880 | 1 | 1 | Potter, Mrs. Thomas Jr (Lily Alexenia Wilson) | female | 56.0 | 0 | 1 | 11767 | 83.1583 | C50 | C | 0 | 0.0 | 0.0 |
880 | 881 | 1 | 2 | Shelley, Mrs. William (Imanita Parrish Hall) | female | 25.0 | 0 | 1 | 230433 | 26.0000 | NaN | S | 0 | 0.0 | 1.0 |
881 | 882 | 0 | 3 | Markun, Mr. Johann | male | 33.0 | 0 | 0 | 349257 | 7.8958 | NaN | S | 1 | 0.0 | 1.0 |
882 | 883 | 0 | 3 | Dahlberg, Miss. Gerda Ulrika | female | 22.0 | 0 | 0 | 7552 | 10.5167 | NaN | S | 0 | 0.0 | 1.0 |
883 | 884 | 0 | 2 | Banfield, Mr. Frederick James | male | 28.0 | 0 | 0 | C.A./SOTON 34068 | 10.5000 | NaN | S | 1 | 0.0 | 1.0 |
884 | 885 | 0 | 3 | Sutehall, Mr. Henry Jr | male | 25.0 | 0 | 0 | SOTON/OQ 392076 | 7.0500 | NaN | S | 1 | 0.0 | 1.0 |
885 | 886 | 0 | 3 | Rice, Mrs. William (Margaret Norton) | female | 39.0 | 0 | 5 | 382652 | 29.1250 | NaN | Q | 0 | 1.0 | 0.0 |
886 | 887 | 0 | 2 | Montvila, Rev. Juozas | male | 27.0 | 0 | 0 | 211536 | 13.0000 | NaN | S | 1 | 0.0 | 1.0 |
887 | 888 | 1 | 1 | Graham, Miss. Margaret Edith | female | 19.0 | 0 | 0 | 112053 | 30.0000 | B42 | S | 0 | 0.0 | 1.0 |
888 | 889 | 0 | 3 | Johnston, Miss. Catherine Helen "Carrie" | female | NaN | 1 | 2 | W./C. 6607 | 23.4500 | NaN | S | 0 | 0.0 | 1.0 |
889 | 890 | 1 | 1 | Behr, Mr. Karl Howell | male | 26.0 | 0 | 0 | 111369 | 30.0000 | C148 | C | 1 | 0.0 | 0.0 |
890 | 891 | 0 | 3 | Dooley, Mr. Patrick | male | 32.0 | 0 | 0 | 370376 | 7.7500 | NaN | Q | 1 | 1.0 | 0.0 |
891 rows × 15 columns
In [38]:
# create dummy variables for multiple categories
# drop_first=True handles k - 1
pd.get_dummies(train, columns=['Sex', 'Embarked'], drop_first=True)
# this drops original Sex and Embarked columns
# and creates dummy variables
Out[38]:
PassengerId | Survived | Pclass | Name | Age | SibSp | Parch | Ticket | Fare | Cabin | Sex_male | Sex_male | Embarked_Q | Embarked_S | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 0 | 3 | Braund, Mr. Owen Harris | 22.0 | 1 | 0 | A/5 21171 | 7.2500 | NaN | 1 | 1.0 | 0.0 | 1.0 |
1 | 2 | 1 | 1 | Cumings, Mrs. John Bradley (Florence Briggs Th... | 38.0 | 1 | 0 | PC 17599 | 71.2833 | C85 | 0 | 0.0 | 0.0 | 0.0 |
2 | 3 | 1 | 3 | Heikkinen, Miss. Laina | 26.0 | 0 | 0 | STON/O2. 3101282 | 7.9250 | NaN | 0 | 0.0 | 0.0 | 1.0 |
3 | 4 | 1 | 1 | Futrelle, Mrs. Jacques Heath (Lily May Peel) | 35.0 | 1 | 0 | 113803 | 53.1000 | C123 | 0 | 0.0 | 0.0 | 1.0 |
4 | 5 | 0 | 3 | Allen, Mr. William Henry | 35.0 | 0 | 0 | 373450 | 8.0500 | NaN | 1 | 1.0 | 0.0 | 1.0 |
5 | 6 | 0 | 3 | Moran, Mr. James | NaN | 0 | 0 | 330877 | 8.4583 | NaN | 1 | 1.0 | 1.0 | 0.0 |
6 | 7 | 0 | 1 | McCarthy, Mr. Timothy J | 54.0 | 0 | 0 | 17463 | 51.8625 | E46 | 1 | 1.0 | 0.0 | 1.0 |
7 | 8 | 0 | 3 | Palsson, Master. Gosta Leonard | 2.0 | 3 | 1 | 349909 | 21.0750 | NaN | 1 | 1.0 | 0.0 | 1.0 |
8 | 9 | 1 | 3 | Johnson, Mrs. Oscar W (Elisabeth Vilhelmina Berg) | 27.0 | 0 | 2 | 347742 | 11.1333 | NaN | 0 | 0.0 | 0.0 | 1.0 |
9 | 10 | 1 | 2 | Nasser, Mrs. Nicholas (Adele Achem) | 14.0 | 1 | 0 | 237736 | 30.0708 | NaN | 0 | 0.0 | 0.0 | 0.0 |
10 | 11 | 1 | 3 | Sandstrom, Miss. Marguerite Rut | 4.0 | 1 | 1 | PP 9549 | 16.7000 | G6 | 0 | 0.0 | 0.0 | 1.0 |
11 | 12 | 1 | 1 | Bonnell, Miss. Elizabeth | 58.0 | 0 | 0 | 113783 | 26.5500 | C103 | 0 | 0.0 | 0.0 | 1.0 |
12 | 13 | 0 | 3 | Saundercock, Mr. William Henry | 20.0 | 0 | 0 | A/5. 2151 | 8.0500 | NaN | 1 | 1.0 | 0.0 | 1.0 |
13 | 14 | 0 | 3 | Andersson, Mr. Anders Johan | 39.0 | 1 | 5 | 347082 | 31.2750 | NaN | 1 | 1.0 | 0.0 | 1.0 |
14 | 15 | 0 | 3 | Vestrom, Miss. Hulda Amanda Adolfina | 14.0 | 0 | 0 | 350406 | 7.8542 | NaN | 0 | 0.0 | 0.0 | 1.0 |
15 | 16 | 1 | 2 | Hewlett, Mrs. (Mary D Kingcome) | 55.0 | 0 | 0 | 248706 | 16.0000 | NaN | 0 | 0.0 | 0.0 | 1.0 |
16 | 17 | 0 | 3 | Rice, Master. Eugene | 2.0 | 4 | 1 | 382652 | 29.1250 | NaN | 1 | 1.0 | 1.0 | 0.0 |
17 | 18 | 1 | 2 | Williams, Mr. Charles Eugene | NaN | 0 | 0 | 244373 | 13.0000 | NaN | 1 | 1.0 | 0.0 | 1.0 |
18 | 19 | 0 | 3 | Vander Planke, Mrs. Julius (Emelia Maria Vande... | 31.0 | 1 | 0 | 345763 | 18.0000 | NaN | 0 | 0.0 | 0.0 | 1.0 |
19 | 20 | 1 | 3 | Masselmani, Mrs. Fatima | NaN | 0 | 0 | 2649 | 7.2250 | NaN | 0 | 0.0 | 0.0 | 0.0 |
20 | 21 | 0 | 2 | Fynney, Mr. Joseph J | 35.0 | 0 | 0 | 239865 | 26.0000 | NaN | 1 | 1.0 | 0.0 | 1.0 |
21 | 22 | 1 | 2 | Beesley, Mr. Lawrence | 34.0 | 0 | 0 | 248698 | 13.0000 | D56 | 1 | 1.0 | 0.0 | 1.0 |
22 | 23 | 1 | 3 | McGowan, Miss. Anna "Annie" | 15.0 | 0 | 0 | 330923 | 8.0292 | NaN | 0 | 0.0 | 1.0 | 0.0 |
23 | 24 | 1 | 1 | Sloper, Mr. William Thompson | 28.0 | 0 | 0 | 113788 | 35.5000 | A6 | 1 | 1.0 | 0.0 | 1.0 |
24 | 25 | 0 | 3 | Palsson, Miss. Torborg Danira | 8.0 | 3 | 1 | 349909 | 21.0750 | NaN | 0 | 0.0 | 0.0 | 1.0 |
25 | 26 | 1 | 3 | Asplund, Mrs. Carl Oscar (Selma Augusta Emilia... | 38.0 | 1 | 5 | 347077 | 31.3875 | NaN | 0 | 0.0 | 0.0 | 1.0 |
26 | 27 | 0 | 3 | Emir, Mr. Farred Chehab | NaN | 0 | 0 | 2631 | 7.2250 | NaN | 1 | 1.0 | 0.0 | 0.0 |
27 | 28 | 0 | 1 | Fortune, Mr. Charles Alexander | 19.0 | 3 | 2 | 19950 | 263.0000 | C23 C25 C27 | 1 | 1.0 | 0.0 | 1.0 |
28 | 29 | 1 | 3 | O'Dwyer, Miss. Ellen "Nellie" | NaN | 0 | 0 | 330959 | 7.8792 | NaN | 0 | 0.0 | 1.0 | 0.0 |
29 | 30 | 0 | 3 | Todoroff, Mr. Lalio | NaN | 0 | 0 | 349216 | 7.8958 | NaN | 1 | 1.0 | 0.0 | 1.0 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
861 | 862 | 0 | 2 | Giles, Mr. Frederick Edward | 21.0 | 1 | 0 | 28134 | 11.5000 | NaN | 1 | 1.0 | 0.0 | 1.0 |
862 | 863 | 1 | 1 | Swift, Mrs. Frederick Joel (Margaret Welles Ba... | 48.0 | 0 | 0 | 17466 | 25.9292 | D17 | 0 | 0.0 | 0.0 | 1.0 |
863 | 864 | 0 | 3 | Sage, Miss. Dorothy Edith "Dolly" | NaN | 8 | 2 | CA. 2343 | 69.5500 | NaN | 0 | 0.0 | 0.0 | 1.0 |
864 | 865 | 0 | 2 | Gill, Mr. John William | 24.0 | 0 | 0 | 233866 | 13.0000 | NaN | 1 | 1.0 | 0.0 | 1.0 |
865 | 866 | 1 | 2 | Bystrom, Mrs. (Karolina) | 42.0 | 0 | 0 | 236852 | 13.0000 | NaN | 0 | 0.0 | 0.0 | 1.0 |
866 | 867 | 1 | 2 | Duran y More, Miss. Asuncion | 27.0 | 1 | 0 | SC/PARIS 2149 | 13.8583 | NaN | 0 | 0.0 | 0.0 | 0.0 |
867 | 868 | 0 | 1 | Roebling, Mr. Washington Augustus II | 31.0 | 0 | 0 | PC 17590 | 50.4958 | A24 | 1 | 1.0 | 0.0 | 1.0 |
868 | 869 | 0 | 3 | van Melkebeke, Mr. Philemon | NaN | 0 | 0 | 345777 | 9.5000 | NaN | 1 | 1.0 | 0.0 | 1.0 |
869 | 870 | 1 | 3 | Johnson, Master. Harold Theodor | 4.0 | 1 | 1 | 347742 | 11.1333 | NaN | 1 | 1.0 | 0.0 | 1.0 |
870 | 871 | 0 | 3 | Balkic, Mr. Cerin | 26.0 | 0 | 0 | 349248 | 7.8958 | NaN | 1 | 1.0 | 0.0 | 1.0 |
871 | 872 | 1 | 1 | Beckwith, Mrs. Richard Leonard (Sallie Monypeny) | 47.0 | 1 | 1 | 11751 | 52.5542 | D35 | 0 | 0.0 | 0.0 | 1.0 |
872 | 873 | 0 | 1 | Carlsson, Mr. Frans Olof | 33.0 | 0 | 0 | 695 | 5.0000 | B51 B53 B55 | 1 | 1.0 | 0.0 | 1.0 |
873 | 874 | 0 | 3 | Vander Cruyssen, Mr. Victor | 47.0 | 0 | 0 | 345765 | 9.0000 | NaN | 1 | 1.0 | 0.0 | 1.0 |
874 | 875 | 1 | 2 | Abelson, Mrs. Samuel (Hannah Wizosky) | 28.0 | 1 | 0 | P/PP 3381 | 24.0000 | NaN | 0 | 0.0 | 0.0 | 0.0 |
875 | 876 | 1 | 3 | Najib, Miss. Adele Kiamie "Jane" | 15.0 | 0 | 0 | 2667 | 7.2250 | NaN | 0 | 0.0 | 0.0 | 0.0 |
876 | 877 | 0 | 3 | Gustafsson, Mr. Alfred Ossian | 20.0 | 0 | 0 | 7534 | 9.8458 | NaN | 1 | 1.0 | 0.0 | 1.0 |
877 | 878 | 0 | 3 | Petroff, Mr. Nedelio | 19.0 | 0 | 0 | 349212 | 7.8958 | NaN | 1 | 1.0 | 0.0 | 1.0 |
878 | 879 | 0 | 3 | Laleff, Mr. Kristo | NaN | 0 | 0 | 349217 | 7.8958 | NaN | 1 | 1.0 | 0.0 | 1.0 |
879 | 880 | 1 | 1 | Potter, Mrs. Thomas Jr (Lily Alexenia Wilson) | 56.0 | 0 | 1 | 11767 | 83.1583 | C50 | 0 | 0.0 | 0.0 | 0.0 |
880 | 881 | 1 | 2 | Shelley, Mrs. William (Imanita Parrish Hall) | 25.0 | 0 | 1 | 230433 | 26.0000 | NaN | 0 | 0.0 | 0.0 | 1.0 |
881 | 882 | 0 | 3 | Markun, Mr. Johann | 33.0 | 0 | 0 | 349257 | 7.8958 | NaN | 1 | 1.0 | 0.0 | 1.0 |
882 | 883 | 0 | 3 | Dahlberg, Miss. Gerda Ulrika | 22.0 | 0 | 0 | 7552 | 10.5167 | NaN | 0 | 0.0 | 0.0 | 1.0 |
883 | 884 | 0 | 2 | Banfield, Mr. Frederick James | 28.0 | 0 | 0 | C.A./SOTON 34068 | 10.5000 | NaN | 1 | 1.0 | 0.0 | 1.0 |
884 | 885 | 0 | 3 | Sutehall, Mr. Henry Jr | 25.0 | 0 | 0 | SOTON/OQ 392076 | 7.0500 | NaN | 1 | 1.0 | 0.0 | 1.0 |
885 | 886 | 0 | 3 | Rice, Mrs. William (Margaret Norton) | 39.0 | 0 | 5 | 382652 | 29.1250 | NaN | 0 | 0.0 | 1.0 | 0.0 |
886 | 887 | 0 | 2 | Montvila, Rev. Juozas | 27.0 | 0 | 0 | 211536 | 13.0000 | NaN | 1 | 1.0 | 0.0 | 1.0 |
887 | 888 | 1 | 1 | Graham, Miss. Margaret Edith | 19.0 | 0 | 0 | 112053 | 30.0000 | B42 | 0 | 0.0 | 0.0 | 1.0 |
888 | 889 | 0 | 3 | Johnston, Miss. Catherine Helen "Carrie" | NaN | 1 | 2 | W./C. 6607 | 23.4500 | NaN | 0 | 0.0 | 0.0 | 1.0 |
889 | 890 | 1 | 1 | Behr, Mr. Karl Howell | 26.0 | 0 | 0 | 111369 | 30.0000 | C148 | 1 | 1.0 | 0.0 | 0.0 |
890 | 891 | 0 | 3 | Dooley, Mr. Patrick | 32.0 | 0 | 0 | 370376 | 7.7500 | NaN | 1 | 1.0 | 1.0 | 0.0 |
891 rows × 14 columns
Tags:
pandas