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.
Diese Übung ist Teil des Kurses
Building Dashboards with Dash and Plotly
Anleitung zur Übung
- Create a line graph object called
line_graphusing aplotly.expressfunction. - Set the DataFrame to
ecom_salesand give the graph a title of'Total Sales by Country and Month'. - Use the
colorargument to create a separate line per country using the'Country'column.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
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()