Cruising Through US Traffic Insights with Pandas Pivot Table
Cruising Through US Traffic Insights with Pandas Pivot Table Data Science Project
Data Wrangling with Pandas

Cruising Through US Traffic Insights with Pandas Pivot Table

In this lab, you'll analyze US traffic accidents using Pandas' Pivot Tables and Crosstabs. Learn to group data, perform aggregations, and handle missing values. By the end, you'll gain hands-on experience in extracting insights from complex datasets, improving your data analysis skills.
Start this project
Cruising Through US Traffic Insights with Pandas Pivot TableCruising Through US Traffic Insights with Pandas Pivot Table
Project Created by

Anurag Verma

Project Activities

All our Data Science projects include bite-sized activities to test your knowledge and practice in an environment with constant feedback.

All our activities include solutions with explanations on how they work and why we chose them.

codevalidated

Using Pivot Tables: Calculate the number of accidents in each `Severity`.

Store the resulting series in the variable no_accidents_per_severity.

codevalidated

Using Pivot Tables: Analyze the relationship between `Severity` of Accidents and `Weather_Condition` by calculating the number of accidents in each combination.

Store the resulting dataframe in the variable severity_weather_no_of_accidents.

You should fill NaN values with 0.

Your result should look similar to this dataframe:

activity2-answer

codevalidated

Using Pivot Tables: Analyze the relationship between `Severity` of Accidents and `Wind_Direction` by calculating the average `Temperature(F)` in each combination.

Store the resulting dataframe in the variable average_temp_severity_wind.

Your result should look similar to this dataframe:

activity3-answer

codevalidated

Using Pivot Tables: Calculate the maximum `Wind_Speed(mph)` in each `State`.

Store the resulting dataframe in the variable max_wind_speed_per_state.

Your result should look similar to this dataframe:

activity4-answer

codevalidated

Using Pivot Tables: Analyze the relationship between the `City` of the Accident and `Traffic_Signal` by calculating the minimum `Humidity(%)`, `Pressure(in)`, and `Visibility(mi)` in each combination and calculate the minimum between all in each combinati…

Store the resulting dataframe in the variable min_humidity_pressure_visibility_city_traffic.

You should fill NaN values with 0 and name the margins with Min. of All.

Your result should look similar to this dataframe:

activity5-answer

codevalidated

Using Pivot Tables: Analyze the relationship between the `County` of the Accident and `Sunrise_Sunset` & `Source` by calculating the mean of `Distance(mi)` & the mean of `Wind_Speed(mph)` in each combination.

Store the resulting dataframe in the variable avg_distance_wind_county_sunrise_source.

You should fill NaN values with 0.

Your result should look similar to this dataframe:

activity6-answer

codevalidated

Using Crosstabs: Calculate the median `Visibility(mi)` for each `Weather_Condition` and `Civil_Twilight` combination.

Store the resulting crosstab in the variable median_visibility_weather_twilight_cross_tab.

You should fill NaN values with 0.

Your result should look similar to this crosstab:

activity10-answer

codevalidated

Using Crosstabs: Find the top 5 cities with the highest number of accidents for each `State`.

Store the resulting crosstab in the variable top_cities_crosstab.

Your result should look similar to this crosstab:

activity11-answer

codevalidated

Using Crosstabs: Calculate the average `Visibility(mi)` for each `Weather_Condition` and `Wind_Direction` combination.

Store the resulting crosstab in the variable average_visibility_weather_wind_crosstab.

Your result should look similar to this crosstab:

activity13-answer

Cruising Through US Traffic Insights with Pandas Pivot TableCruising Through US Traffic Insights with Pandas Pivot Table
Project Created by

Anurag Verma

What's up, friends! πŸ‘‹ I'm a computer science student about to finish my last year of college. πŸŽ“ I LOVE writing code! ❀️ It makes me so happy! πŸ˜„ Whether I'm goofing in notebooks πŸ““ or coding in Python 🐍, writing programs is a blast! πŸ’₯

What's up, friends! πŸ‘‹ I'm a computer science student about to finish my last year of college. πŸŽ“ I LOVE writing code! ❀️ It makes me so happy! πŸ˜„ Whether I'm goofing in notebooks πŸ““ or coding in Python 🐍, writing programs is a blast! πŸ’₯

This project is part of

Data Wrangling with Pandas

Explore other projects