Google Colab offers a powerful Python environment with free access to GPUs, ideal for machine learning and data analysis tasks. If you're working with datasets from Kaggle, you can easily connect the two platforms using the Kaggle API.
In this guide, we'll show you how to import Kaggle datasets into Google Colab in five simple steps.

kaggle.json to your computer
kaggle.json file to your local system.
kaggle.json to ColabUse the below code in your Colab notebook to upload the kaggle.json file.
from google.colab import files
files.upload() # Choose kaggle.json when prompted
Move the file to the correct location and set permissions:
# Create the directory if it doesn't exist
!mkdir -p ~/.kaggle
# Move kaggle.json to the correct directory. Assumes kaggle.json is in the current working directory.
# If your kaggle.json is in a different location, please update the path below.
!mv kaggle.json ~/.kaggle/
# Set permissions for the kaggle.json file
!chmod 600 ~/.kaggle/kaggle.json

Go to the Kaggle dataset page and copy the dataset name from the URL. For example, for:
kagglehub.dataset_download("yasserh/titanic-dataset")
The dataset path is: yasserh/titanic-dataset
Use the command below to download:
!kaggle datasets download -d yasserh/titanic-dataset
!unzip -q titanic-dataset.zip
Remove other files
# Remove the zip file after extraction
!rm titanic-dataset.zip
# Remove other metadata files if they exist and are not needed
!rm -f titanic-dataset.zip.json
Load Dataset by using Pandas
import pandas as pd
df = pd.read_csv("Titanic-Dataset.csv")
df.head()
How many rows and columns are there in Dataset ?
# Get the total number of rows and columns
num_rows, num_cols = df.shape
print(f"Total number of rows: {num_rows}")
print(f"Total number of columns: {num_cols}")
Enhance your notebook using IPyWidgets for sliders, buttons, and more.
Explore IPyWidgets →
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.