ComenzarEmpieza gratis

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.

Este ejercicio forma parte del curso

Building Dashboards with Dash and Plotly

Ver curso

Instrucciones del ejercicio

  • 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.

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

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()
Editar y ejecutar código