This project focuses on large-scale data processing and visualization using Apache Spark and Docker. We analyze Japanese visa issuance data across multiple years and countries to uncover insights about trends, regional growth patterns, and more.
SparkClusters/
│
├── src/
│ ├── visualisation.py # Main PySpark script for data processing and visualization
│ ├── visa_number_in_japan.csv # Input dataset containing visa data
│ ├── requirements.txt # Required Python dependencies for visualization
│ └── Dockerfile.spark # Dockerfile used to build custom Spark image
│
├── spark-clusters_key.pem # SSH private key for accessing the Azure VM
├── docker-compose.yml # Compose file to launch Spark Master and Workers
├── upload_files.sh # Script to upload project files to Azure VM
├── download_files.sh # Script to download output files and logs from VM
├── run_and_log.sh # Shell script to execute the Spark job and save logs
└── README.md # This documentation file
The goal of this project is to perform end-to-end big data processing and visual analytics using Apache Spark deployed inside Docker containers on a remote Azure Virtual Machine (VM). The process includes:
- Uploading the dataset and code from a local machine to the Azure VM.
- Running a Spark cluster using Docker Compose to simulate distributed processing.
- Cleaning and transforming the dataset using PySpark.
- Generating multiple insightful visualizations using Plotly.
- Saving results in HTML format and downloading them back to the local machine.
- Logging the Spark job execution for monitoring and debugging.
Use upload_files.sh to securely upload source code, input CSV, Docker files, and the requirements list to the VM:
scp -i spark-clusters_key.pem -r ./src/* azureuser@<vm_ip>:/home/azureuser/spark-cluster-uploadNavigate to the project directory on your Azure VM and bring up the cluster:
cd ~/spark-cluster-upload
sudo docker compose up -d --buildThis launches one Spark master and four worker containers defined in docker-compose.yml, all using the image built with Dockerfile.spark.
To execute the PySpark job (visualisation.py) inside the Spark cluster and log the output:
./run_and_log.shThe job will process the visa data and generate HTML visualizations under /home/azureuser/output, while logs are saved in /home/azureuser/logs.
Use download_files.sh to bring all generated HTML files and logs back to your local machine:
scp -i spark-clusters_key.pem /home/azureuser/spark-cluster-upload/output/*.html ./src/output/
scp -i spark-clusters_key.pem /home/azureuser/logs/*.txt ./src/output/The following analyses are performed in visualisation.py using PySpark and Plotly:
- Line Chart - Yearly visa issuance trends across continents.
- Bar Chart - Top 10 countries with most visas issued in 2017.
- Choropleth Map - Animated map showing visa distribution by country from 2006 to 2017.
- Line Chart - Year-over-year growth rate of visas per continent.
- Bar Chart with Labels - Peak visa issuance year for each continent.
All charts are saved as HTML files in the output directory and can be opened in any browser.
-
visualisation.py: Core processing script that:- Loads and cleans visa CSV data
- Corrects country names using fuzzy matching
- Maps countries to continents using
pycountryandpycountry_convert - Aggregates visa numbers by year, country, and continent
- Uses Spark SQL queries for grouping, filtering, and ranking
- Converts PySpark DataFrames to Pandas for visualization
- Generates five different visualizations using Plotly and writes them as
.htmlfiles - Saves a cleaned version of the data to a CSV file in the output directory
-
Dockerfile.spark: Defines a custom Spark image based on Bitnami Spark, installs Python3 and required packages usingpip3 install -r requirements.txt. -
docker-compose.yml: Orchestrates container deployment for the Spark Master and 4 Spark Workers, exposing necessary ports and linking nodes. -
requirements.txt: Specifies all required Python packages:plotly,pycountry,pycountry-convert, andfuzzywuzzy. -
run_and_log.sh: A shell script that:- Creates a
logsfolder (if it doesn't exist) - Submits the Spark job using
spark-submiton one of the worker containers - Redirects the logs with a timestamp to the
logsfolder for auditing or debugging
- Creates a
-
upload_files.sh: Usesscpto recursively upload thesrc/folder (dataset + code + config) to Azure VM'sspark-cluster-uploaddirectory. -
download_files.sh: Usesscpto recursively download all.htmlvisualizations and.txtlog files from VM back to your local machine. -
spark-clusters_key.pem: SSH private key file used for authentication with the remote VM.
- Apache Spark: For distributed big data processing
- Docker + Docker Compose: For containerized cluster orchestration
- Plotly: For interactive visualizations
- Azure VM: For remote infrastructure
- PySpark: Python API for Apache Spark
This project demonstrates:
- Data cleaning, transformation, and enrichment at scale
- Country-to-continent mapping using fuzzy logic
- Complex multi-visual analytics pipeline using Spark and Plotly
- End-to-end automation with Docker and SSH
- Logging and traceability of analytics jobs
-
Data Ingestion:
- The raw CSV file
visa_number_in_japan.csvis read using PySpark'sread.csv()method. - Column names are standardized by removing whitespace and special characters.
- The raw CSV file
-
Data Cleaning:
- Null columns are dropped.
- Invalid or misspelled country names are corrected using a fuzzy matching function (
fuzzywuzzy.process.extractOne). - Manual overrides are used for names not correctly matched by fuzzy logic.
-
Enrichment:
- Each country is mapped to a continent using
pycountry_convertto enhance geographic analytics. - A new column
continentis added to the DataFrame.
- Each country is mapped to a continent using
-
Spark SQL Processing:
- The cleaned and enriched data is registered as a temporary global SQL table (
global_temp.japan_visa). - SQL queries are used to group data by year, country, and continent.
- Year-over-year calculations and ranking (peak year per continent) are performed using Spark window functions (
lag,row_number).
- The cleaned and enriched data is registered as a temporary global SQL table (
-
Visualization:
- For each visual, the Spark DataFrame is converted to Pandas using
.toPandas(). - Visuals include line plots, choropleth maps, and grouped bar charts using Plotly Express.
- These are saved as
.htmlfiles in theoutput/directory for easy viewing in any browser.
- For each visual, the Spark DataFrame is converted to Pandas using
-
Execution & Logging:
run_and_log.shruns the Spark job and stores logs with a timestamp insidelogs/.- This log file captures runtime Spark details, warnings, and errors for transparency and troubleshooting.
-
Output Handling:
- HTML visuals and the cleaned CSV are stored in the
output/folder inside the VM. download_files.shhelps retrieve these artifacts back to your localsrc/outputdirectory.
- HTML visuals and the cleaned CSV are stored in the
Chiranjit — Master’s Student in Information Systems @ Northeastern University, aspiring Data Engineer
This project is open-source and licensed under the MIT License.
If you found this project insightful or useful, please ⭐ the repository!
