A DataFrame is Pandas’ object for storing a table with multiple columns. A Series holds one column, while a DataFrame holds several columns and rows. section 13.1
Load a CSV into a DataFrame with pandas.read_csv(). For the Titanic data, raw_data contains passenger details such as class, age, fare, cabin, embarkation, and survival. Pandas adds row numbering by default; index_col="PassengerId" instead uses the dataset’s passenger identifiers as the index. section 13.1
Once loaded, inspect and select the table with simple operations:
- Use len(raw_data) to count rows and raw_data.columns to inspect column labels. section 13.1
- Select one column as a Series with raw_data['Survived'], or select several columns with raw_data[['Name', 'Age']]. section 13.1
- Save a DataFrame to CSV and load it again for later cleaning or preprocessing. section 13.1
Table 13.1 The Titanic dataset contains information on the passengers on the Titanic, including whether they survived. Here we use Pandas to open the dataset and print out its rows and columns. Notice that it has 891 rows and 12 columns. (view table figure)
| PassengerId |
Survived |
Pclass |
Name |
Sex |
Age |
SibSp |
Parch |
Ticket |
Fare |
Cabin |
Embarked |
| 1 |
0 |
3 |
Braund, Mr. Owen Harris |
male |
22.0 |
1 |
0 |
A/5 21171 |
7.2500 |
NaN |
S |
| 2 |
1 |
1 |
Cumings, Mrs. John Bradley (Florence Briggs Th... |
female |
38.0 |
1 |
0 |
PC 17599 |
71.2833 |
C85 |
C |
| 3 |
1 |
3 |
Heikkinen, Miss Laina |
female |
26.0 |
0 |
0 |
STON/O2. 3101282 |
7.9250 |
NaN |
S |
| ... |
... |
... |
... |
... |
... |
... |
... |
... |
... |
... |
... |
| 890 |
1 |
1 |
Behr, Mr. Karl Howell |
male |
26.0 |
0 |
0 |
111369 |
30.0000 |
C148 |
C |
| 891 |
0 |
3 |
Dooley, Mr. Patrick |
male |
32.0 |
0 |
0 |
370376 |
7.7500 |
NaN |
Q |
Browse the Titanic table to see its labeled rows, twelve columns, missing cabin values, and passenger records. section 13.1


















