How you obtain the Titanic dataset from Kaggle, post it to Google Colab, then import it into a Pandas DataFrame. The first few rows will be displayed using the head()
method.
-
Go to Kaggle:
- Visit the Titanic dataset page on Kaggle.
-
Download the Dataset:
- Click on the "Download All" button to download the dataset as a ZIP file.
- Extract the ZIP file on your computer to access the
train.csv
file. - File: train.csv
-
Open Google Colab:
- Go to Google Colab and create a new notebook if you haven't already.
-
Upload the File:
- In Colab, click on the folder icon on the left sidebar to open the file explorer.
- Click on the upload icon (a paperclip) at the top of the file explorer.
- Select the
train.csv
file from your computer and upload it.
-
Import Required Libraries:
- In the first code cell, type the following code to import pandas:
import pandas as pd
- In the first code cell, type the following code to import pandas:
-
Load the Dataset:
- In the next code cell, type the following code to load the dataset into a pandas DataFrame:
df = pd.read_csv('train.csv')
- In the next code cell, type the following code to load the dataset into a pandas DataFrame:
-
Display the First Few Rows:
- In the next code cell, type the following code to display the first few rows of the DataFrame:
df.head()
- In the next code cell, type the following code to display the first few rows of the DataFrame:
-
Open Google Colab:
- Go to Google Colab.
-
Create a New Notebook:
- Click on "File" > "New Notebook".
-
Import Necessary Libraries:
- In the first code cell, import the necessary libraries:
import pandas as pd
- In the first code cell, import the necessary libraries:
-
Download the Dataset from GitHub:
- In the next code cell, use the following code to download the dataset using
wget
:!wget https://raw.githubusercontent.com/drshahizan/dataset/main/titanic/train.csv -O train.csv
- In the next code cell, use the following code to download the dataset using
-
Load the Dataset into a Pandas DataFrame:
- In the next code cell, load the dataset and display the first few rows:
df = pd.read_csv('train.csv') df.head()
- In the next code cell, load the dataset and display the first few rows:
By following these steps, you will have successfully downloaded the Titanic dataset, uploaded it to Google Colab, loaded it into a pandas DataFrame, and displayed the first few rows using the head()
method.
Please create an Issue for any improvements, suggestions or errors in the content.
You can also contact me using Linkedin for any other queries or feedback.