A complete data engineering and analytics project using the US Accidents dataset, covering extraction, transformation, and loading into a PostgreSQL database, followed by SQL-based analysis and Python-powered visualizations.
TrafficAccidents-ETL-Analysis/
├── data/ # Raw dataset (ignored in Git)
├── database/
│ ├── create_schema.sql # Table schema for PostgreSQL
│ └── insert_data.py # CSV-to-Postgres script
├── scripts/
│ └── clean_transform.py # ETL transformation script
├── notebooks/
│ ├── exploratory_analysis.ipynb # All 10 visual plots
│ └── advanced_queries.ipynb # Raw SQL insights
├── visualizations/ # Saved plots
├── main.py # Runs the full ETL pipeline
├── requirements.txt # Python dependencies
├── .env # DB credentials (excluded from Git)
└── README.md # Project overview
-
Source: Kaggle: US Accidents (2016–2023)
-
Size: 7+ million rows
-
Fields include:
- Start/End Time
- Severity
- City, State
- Weather Condition
- Visibility, Temperature, Wind Speed
- Accident Duration (calculated)
- 📥 Extract: CSV loaded using Pandas
- 🧹 Transform: Cleaned nulls, calculated accident duration, converted timestamps
- 🏗️ Load: Inserted into PostgreSQL using SQLAlchemy
Run the full pipeline:
python main.pyStored in the notebooks/visualizations/ folder and generated via Jupyter:
-
Accidents by State
-
Severity Distribution
-
Accident Duration Histogram
-
Top Cities by Accidents
-
Weather Conditions by State
-
Hourly Accident Distribution
-
Weekday vs Weekend Accidents
-
Monthly Average Duration
-
Severity by Weather Condition
-
Wind Speed vs Severity
Found in notebooks/advanced_queries.ipynb:
- Top cities with most accidents
- Average duration per state
- Severity × Weather correlation
- Time-based aggregations (hour, weekday, month)
- Weather/visibility/wind effect on severity
- Language: Python 3.10+
- Database: PostgreSQL
- Libraries: Pandas, SQLAlchemy, Matplotlib, Seaborn, Dotenv
- Notebook: Jupyter
-
Clone repo:
git clone https://github.com/ChaiiShree/sql.git cd TrafficAccidents-ETL-Analysis -
Create
.envfile:DATABASE_URL=postgresql://username:password@localhost:5432/dbname -
Set up environment:
python -m venv venv venv/Scripts/activate # On Windows pip install -r requirements.txt -
Download dataset from Kaggle into
data/ -
Run ETL:
python main.py
-
Launch notebooks:
jupyter notebook
This project is licensed under the MIT License. Dataset credit: © Kaggle – US Accidents









