analyse_titanic
analyse the titanic data
Thinking
Clarifying dataset needs
I need to identify which dataset the user is referring to. It looks like they might want to analyze data similar to the Titanic dataset from seaborn, but the current notebook doesn't have it loaded. I should confirm what specific data file they intend to use. I can load the seaborn dataset if there’s internet access, but it seems I need a file path or clarification from the user first. Let's sort that out!
i have already put the titatnic dataset in the working directory in the mljar studio same path as the notebook @analys_titanic.iipynb
Thinking
Clarifying file issues
I need to check for available files. There's a mention of a path being unavailable, and there's a conventional titanic.csv, but I don't have the exact filename. It seems I should clarify that. I could try to list files programmatically in the working directory. The dataset isn’t loaded yet, and I'd typically load the dataset first, but I can’t do that without the right file name. So, discovery is in order!
I’ll identify the available Titanic data file in the notebook’s working directory.
</>List data files
from pathlib import Path
files = [p.name for p in Path(".").iterdir() if p.is_file()]
[name for name in files if "titanic" in name.lower() or name.lower().endswith((".csv", ".xlsx", ".xls", ".parquet"))]['analyse_titanic.ipynb', 'Titanic-Dataset.csv']
The working directory contains Titanic-Dataset.csv, alongside the notebook. The next step is to load it and verify its schema before analyzing survival patterns.
</>Load Titanic data
import pandas as pd
df = pd.read_csv("Titanic-Dataset.csv")
print(f"Shape: {df.shape}")
columns = df.columns.tolist()
print(f"Columns ({len(columns)}):", columns if len(columns) <= 100 else columns[:100] + ["..."])
df.head()Shape: (891, 12) Columns (12): ['PassengerId', 'Survived', 'Pclass', 'Name', 'Sex', 'Age', 'SibSp', 'Parch', 'Ticket', 'Fare', 'Cabin', 'Embarked']
| 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 |
The file is in the same working directory as the notebook and has been read into df. It contains 891 passenger records with the standard Titanic fields, including the survival target (Survived), demographics (Sex, Age), travel class (Pclass), family counts, fare, cabin, and embarkation port.