This repository contains a Databricks-based big data project for analyzing and predicting airline delays using PySpark. The workflow covers data ingestion, preprocessing, exploratory analysis, visualization, and machine learning on large-scale U.S. flight records.
The project uses the Kaggle dataset airline-delay-and-cancellation-data-2009-2018 and focuses on the 2016, 2017, and 2018 flight data files. The pipeline is designed to run in Databricks with Apache Spark and process millions of records efficiently.
Core stages:
- Download and extract the dataset with the Kaggle API
- Store raw files in a Databricks Unity Catalog volume
- Load yearly CSV files into Spark DataFrames
- Clean and standardize the data
- Engineer features for analysis and classification
- Perform EDA and generate visualizations
- Train delay-prediction models with PySpark ML
- Upload sampled flight data into MongoDB for NoSQL storage
- Python
- Apache Spark / PySpark
- Databricks
- Kaggle API
- MongoDB
- PyMongo
- Matplotlib
- Seaborn
- Pandas
Source dataset:
- Kaggle:
yuanyuwendymu/airline-delay-and-cancellation-data-2009-2018
Years used in this project:
- 2016
- 2017
- 2018
The notebook installs the Kaggle package, authenticates with Kaggle, downloads the airline delay dataset, extracts the archive, and reads the relevant CSV files into Spark DataFrames.
The preprocessing pipeline includes:
- Standardizing column names
- Selecting relevant flight columns
- Removing duplicate rows
- Casting fields to appropriate data types
- Measuring and handling missing values
- Dropping columns with more than 50% missing data
- Filling numeric nulls with averages
- Filling categorical nulls with
"Unknown" - Filtering invalid values and anomalies
Derived fields include:
routeyearmonthdayday_of_weekmonth_namescheduled_dep_houris_delayedflight_statusdelay_category
The analysis section examines:
- Flight volume by year
- Delay and cancellation rates
- Busiest origin and destination airports
- Delay patterns by hour and month
- Airport-level performance
- Distance-based delay behavior
- Taxi time trends
The project generates charts such as:
- Line charts for yearly flight and delay trends
- Bar charts for top airports
- Pie and donut charts for flight status and delay categories
- Density plots for arrival delay distribution
- Heatmaps for correlation analysis
The notebook builds classification models to predict whether a flight is delayed.
Models used:
- Decision Tree Classifier
- Random Forest Classifier
- Gradient Boosted Tree Classifier
Evaluation metrics:
- Accuracy
- Precision
- Recall
- ROC AUC
The repository also includes a NoSQL data-loading script in Upload_Data.py for sending sampled CSV data into MongoDB.
MongoDB workflow:
- Connects to MongoDB using
pymongo.MongoClient - Verifies the connection with a
pingrequest - Uses the database
US_Flight_Cancellation_Delay_History - Uses the collection
flights - Reads sampled CSV files from the
data/directory - Converts each CSV into JSON-like records with Pandas
- Inserts the records into MongoDB with
insert_many
Expected sample files:
data/sample_2016.csvdata/sample_2017.csvdata/sample_2018.csv
This section supports a NoSQL storage use case alongside the Spark-based analytics workflow, making it easier to persist subsets of the flight dataset for document-oriented querying and downstream application use.
Big Data Analytics.ipynb: notebook version of the projectBig Data Analytics.py: exported Databricks notebook as a Python scriptBig Data Analytics.html: exported HTML version of the notebookUpload_Data.py: MongoDB upload script for sampled CSV filesWeb/: static website built from the notebook outputs and visualizationsREADME.md: project documentation
The repository now includes a GitHub Pages workflow that deploys the Web/ folder as a static site.
Expected public URL after deployment:
https://thimira-hansana.github.io/Flight-Delay-Analytics-NoSQL-PySpark/
To publish it:
- Push the repository changes to GitHub.
- In the GitHub repository, open
Settings->Pages. - Under
Build and deployment, setSourcetoGitHub Actions. - Wait for the
Deploy Web To GitHub Pagesworkflow to finish. - Open the Pages URL above.
Notes:
- The workflow runs on pushes to
mainanddev. - It deploys the contents of
Web/directly, so the site opens from the repository Pages URL without extra routing. - If you open the site locally with
file://, the 3D aircraft falls back to a static preview. On GitHub Pages it will load through normal HTTPS requests.
- A Databricks workspace
- A Spark cluster with PySpark support
- Kaggle account and API credentials
- Access to Unity Catalog volumes if using the same storage workflow
- MongoDB instance or MongoDB Atlas cluster for the NoSQL upload step
- Clone this repository.
- Import
Big Data Analytics.ipynbinto Databricks, or useBig Data Analytics.pyas the notebook source. - Install the Kaggle package inside the notebook environment.
- Configure Kaggle authentication securely in Databricks.
- Create or reuse the Unity Catalog volume used for raw data storage.
- Run the notebook cells in order from ingestion through model evaluation.
- For the NoSQL section, install
pymongoandpandas, set your MongoDB connection URI inUpload_Data.py, and run the script after preparing the sample CSV files in thedata/folder.
- The code is written for a Databricks notebook workflow rather than a standalone local Python application.
- Some sections convert Spark results to Pandas for plotting, so driver memory should be sized accordingly.
- Kaggle credentials should be handled securely and should not be committed directly into source files.
- The MongoDB upload script expects sample CSV files and a valid MongoDB URI; connection secrets should be provided securely and not committed to source control.
This project demonstrates an end-to-end big data analytics workflow for airline delay analysis, combining scalable PySpark processing in Databricks with optional MongoDB-based NoSQL storage for sampled flight records.