Ex 4.6 Formatting Bar Chart Labels:

Objective: Learn to add and format bar chart labels.

  1. Create a new Jupyter Notebook file and name it Ex4.6_FormattingBarChartLabels.ipynb.
  2. Work through parts 1 through 4 below and submit your completed Jupyter Notebook (.ipynb) file to the first quiz question on Canvas. Your notebook should include both your code and the corresponding output that match the screengrabs provided below. Be sure to run all cells so that every output appears in the notebook.

Part 1:

  • Use the Cars.csv data file to answer the following question and create the two bar charts shown below.
    • What is the Average Invoice by Vehicle Type? (Sort by Invoice - Greatest to Least)

Expected output: pandas groupby DataFrame showing average Invoice price by Vehicle Type sorted greatest to least

 

Expected output: Plotly Express vertical bar chart with labeled bars showing average Invoice by Vehicle Type

 

Expected output: Plotly Express horizontal bar chart with formatted dollar labels showing average Invoice by Vehicle Type

 

Part 2:

  • Use the Sample - Superstore.xlsx data file to answer the following question and create the bar chart shown below.
    • What is the Average Profit Ratio by Region?
      • Note: Calculate the Profit Ratio before you use groupby.
        • Here’s the formula to use: df['Profit_Ratio'] = df['Profit'] / df['Sales']

Expected output: pandas groupby DataFrame showing Average Profit Ratio by Region from Sample Superstore

 

Expected output: Plotly Express bar chart showing Average Profit Ratio by Region with percentage-formatted labels

 

Part 3:

  • Continue using the Sample - Superstore.xlsx data file to answer the following question and create the bar chart shown below.
    • What are the Average Profits by Subcategory?

Expected output: pandas groupby DataFrame showing Average Profits by Subcategory from Sample Superstore

 

Expected output: Plotly Express bar chart showing Average Profits by Subcategory with formatted dollar labels

 

Part 4:

  • Continue using the Sample - Superstore.xlsx data file to answer the following question and create the bar chart shown below.
    • Which 5 customers generate the highest total profits?

Expected output: pandas groupby DataFrame showing top 5 customers by highest total profits from Sample Superstore

 

Expected output: Plotly Express bar chart showing top 5 customers by highest total profits with formatted dollar labels