Skip to content

wy-chan/Python-Data-Visualization-Project

Repository files navigation

Data Visualization with Python | Course | IBM

Data Visualization with Python - Final Project


Task 1 → Completed Notebook
Task 2 → Completed Codes

Table of Contents:

Task 1: Create visualizations using Matplotib, Seaborn and Folium

Task 2: Create Dashboard with Plotly and Dash



Task 1: Create visualizations using Matplotib, Seaborn and Folium

  • Task 1.1 - Develop a Line chart using the functionality of pandas to show how automobile sales fluctuate from year to year (1 point)

    Line Plot 1

  • Task 1.2 - Plot different lines for categories of vehicle type and analyse the trend to answer the question "Is there a noticeable difference in sales trends between different vehicle types during recession periods?" (1 point)

    Line Plot 2

  • Task 1.3 - Use the functionality of Seaborn Library to create a visualization to compare the sales trend per vehicle type for a recession period with a non-recession period. (1 point)

    Bar Chart

  • Task 1.4 - Use sub plotting to compare the variations in GDP during recession and non-recession period by developing line plots for each period. (2 points)

    sub plotting

  • Task 1.5 - Develop a Bubble plot for displaying the impact of seasonality on Automobile Sales. (1 point)

    Bubble plot

  • Task 1.6 - Use the functionality of Matplotlib to develop a scatter plot to identify the correlation between average vehicle price relate to the sales volume during recessions. (1 point)

    scatter plot

  • Create a pie chart to display the portion of advertising expenditure of XYZAutomotives during recession and non-recession periods. (1 point)

    pie chart 1

  • Task 1.8 - Develop a pie chart to display the total Advertisement expenditure for each vehicle type during recession period. (1 point)

    pie chart 2

  • Task 1.9 - Develop a countplot to analyse the effect of the unemployment rate on vehicle type and sales during the Recession Period. (1 point)

    count plot

Task 2: Create Dashboard with Plotly and Dash

  • Task 2.1 - Create a Dash application and give it a meaningful title. (2 points)

    Title
html.H1("Automobile Sales Statistics Dashboard", style={'textAlign': 'center', 'color': '#503D36', 'font-size': '24px'})

  • Task 2.2 - Add drop-downs to your dashboard with appropriate titles and options. (1 point)

    Drop-downs

 html.Div([
        #TASK 2.2: Add two dropdown menus
        html.Label("Select Statistics:"),
        dcc.Dropdown(
            id='dropdown-statistics',
            options= dropdown_options,
            placeholder='Select a report type',
            value='Select Statistics',
            style={'textAlign': 'center', 'font-size': '20px', 'width': '80%', 'padding':'3px'},
        )
    ]),
    html.Div(dcc.Dropdown(
            id='select-year',
            options=[{'label': i, 'value': i} for i in year_list],
            placeholder='Select Year',
        )),

pre>

  • Task 2.3 - Add a division for output display with appropriate 'id' and 'classname' property. (1 point)

    Output Division

html.Div([
        #TASK 2.3: Add a division for output display
         html.Div(id='output-container', className='chart-grid', style={'display':'flex'}),
        ]),


  • Task 2.4 - Creating Callbacks; Define the callback function to update the input container. (5 points)

    Callback Function

#TASK 2.4: Creating Callbacks
# Define the callback function to update the input container based on the selected statistics
@app.callback(
    Output(component_id='select-year', component_property='disabled'),
    Input(component_id='dropdown-statistics',component_property='value'))

def update_input_container(selected_statistics):
    if selected_statistics =='Yearly Statistics': 
        return False
    else: 
        return True

#Callback for plotting
# Define the callback function to update the input container based on the selected statistics
@app.callback(
    Output(component_id='output-container', component_property='children'),
    [Input(component_id='select-year', component_property='value'), Input(component_id='dropdown-statistics', component_property='value')])


def update_output_container(input_year, selected_statistics):
    if selected_statistics == 'Recession Period Statistics':
        # Filter the data for recession periods
        recession_data = data[data['Recession'] == 1]
      

pre>

  • Task 2.5 - Create and display graphs for Recession Report Statistics. (3 points)

    Recession Report Statistics

#TASK 2.5: Create and display graphs for Recession Report Statistics

#Plot 1 Automobile sales fluctuate over Recession Period (year wise)
        # use groupby to create relevant data for plotting
        yearly_rec=recession_data.groupby('Year')['Automobile_Sales'].mean().reset_index()
        R_chart1 = dcc.Graph(
            figure=px.line(yearly_rec,
                x='Year',
                y='Automobile_Sales',
                title="Average Automobile Sales Fluctuation Over Recession Period"))
#Plot 2 Calculate the average number of vehicles sold by vehicle type       
        # use groupby to create relevant data for plotting
        average_sales = recession_data.groupby('Vehicle_Type')['Automobile_Sales'].mean().reset_index()                           
        R_chart2  = dcc.Graph(
            figure=px.bar(average_sales, 
            x='Vehicle_Type',
            y='Automobile_Sales',
            title="Average Number Of Vehicles Sold By Vehicle Type"))    
# Plot 3 Pie chart for total expenditure share by vehicle type during recessions
        # use groupby to create relevant data for plotting
        exp_rec= recession_data.groupby('Vehicle_Type')['Advertising_Expenditure'].sum().reset_index()
        R_chart3 = dcc.Graph(
                    figure=px.pie(exp_rec,
                    values='Advertising_Expenditure',
                 names='Vehicle_Type',
                 title="Total Expenditure Share By Vehicle Type During Recessions"
                )
        )
# Plot 4 bar chart for the effect of unemployment rate on vehicle type and sales
        average_sales = recession_data.groupby(['unemployment_rate','Vehicle_Type'])['Automobile_Sales'].mean().reset_index()                           
        R_chart4  = dcc.Graph(
                figure=px.bar(average_sales, 
                x='unemployment_rate',
                y='Automobile_Sales',
                color = 'Vehicle_Type',
                title="The Effect Of Unemployment Rate On Vehicle Type And Sales Over Recession Period"))
        return [
            html.Div(className='chart-item', children=[html.Div(children=R_chart1),html.Div(children=R_chart2)]),
            html.Div(className='chart-item', children=[html.Div(children=R_chart3),html.Div(children=R_chart4)])
            ]


  • Task 2.6 - Create and display graphs for Yearly Report Statistics. (2 points)

    Yearly Report Statistics

# TASK 2.6: Create and display graphs for Yearly Report Statistics
 # Yearly Statistic Report Plots                             
    elif (input_year and selected_statistics=='Yearly Statistics') :
        yearly_data = data[data['Year'] == input_year]
                              
#plot 1 Yearly Automobile sales using line chart for the whole period.
        yas= data.groupby('Year')['Automobile_Sales'].mean().reset_index()
        Y_chart1 = dcc.Graph(
                figure=px.line(yas,
                x='Year',
                y='Automobile_Sales',
                title="Average Automobile Sales Fluctuation Over Time"))
          
# Plot 2 Total Monthly Automobile sales using line chart.
        mas= yearly_data.groupby('Month')['Automobile_Sales'].sum().reset_index()
        Y_chart2 = dcc.Graph(
                figure=px.line(mas,
                x='Month',
                y='Automobile_Sales',
                title="Total Monthly Automobile Sales in the year {}" .format(input_year)))

# Plot bar chart for average number of vehicles sold during the given year
        avr_vdata=yearly_data.groupby('Vehicle_Type')['Automobile_Sales'].mean().reset_index()
        Y_chart3 = dcc.Graph(
                figure=px.bar(avr_vdata,
                x='Vehicle_Type',
                y='Automobile_Sales',
                title='Average Vehicles Sold by Vehicle Type in the year {}'.format(input_year)))

# Total Advertisement Expenditure for each vehicle using pie chart
        exp_data=yearly_data.groupby('Vehicle_Type')['Advertising_Expenditure'].sum().reset_index()
        Y_chart4 = dcc.Graph(
                figure=px.pie(exp_data,
                values='Advertising_Expenditure',
                names='Vehicle_Type',
                title='Average Vehicles Sold by Vehicle Type in the year {}'.format(input_year)))

#TASK 2.6: Returning the graphs for displaying Yearly data
        return [
                html.Div(className='chart-item', children=[html.Div(children=Y_chart1),html.Div(children=Y_chart2)]),
                html.Div(className='chart-item', children=[html.Div(children=Y_chart3),html.Div(children=Y_chart4)])
                ]
        
    else:
        return None


- Back to Top | Task 1 | Task 2 -

About

Data Visualization with Python | Course | IBM | Final Project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published