Get startedGet started for free

Line graph of sales by country

You are working for a global e-commerce company that has been using third-party software to build in-house graphics for reporting. They are wondering if open-source libraries would provide better graphics for their reporting purposes.

You jump at the opportunity to design a slick (and interactive!) visual with Plotly. Your first task will be to update their basic line figure, which visualizes the total sales by month and country.

In this exercise and subsequent exercises, the code to load the relevant data and packages has been written for you.

This exercise is part of the course

Building Dashboards with Dash and Plotly

View Course

Exercise instructions

  • Create a line graph object called line_graph using a plotly.express function.
  • Set the DataFrame to ecom_sales and give the graph a title of 'Total Sales by Country and Month'.
  • Use the color argument to create a separate line per country using the 'Country' column.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

import pandas as pd
import plotly.express as px
ecom_sales = pd.read_csv('/usr/local/share/datasets/ecom_sales.csv')
ecom_sales = ecom_sales.groupby(['Year-Month', 'Country'])['OrderValue'].agg('sum').reset_index(name='Total Sales ($)')

# Create the line graph
line_graph = px.____(
  # Set the appropriate DataFrame and title
  data_frame=____, title='____', 
  x='Year-Month', y='Total Sales ($)',
  # Ensure a separate line per country
  color='____')

line_graph.show()
Edit and Run Code