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
-
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









