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 the basic line figure they have, 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 using a plotly.express function.
  • Specify the appropriate DataFrame and give the graph a title of 'Total Sales by Country and Month'.
  • Set the x and y arguments so the x-axis represents time and the y-axis is the total sales amount.
  • Use the color argument to create a separate line per country.

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=____, 
  # Set the x and y arguments
  ____='Year-Month', ____='Total Sales ($)',
  # Ensure a separate line per country
  color=____)

line_graph.show()
Edit and Run Code