For AI agents: the complete documentation index is available at https://docs.ovhcloud.com/es/llms.txt, the full documentation bundle is available at https://docs.ovhcloud.com/es/llms-full.txt, and this page is available as Markdown at https://docs.ovhcloud.com/es/guides/public-cloud/data-platform/tutorials-ecommerce-sales.md.

Prepare online store orders for a sales dashboard

Ver como Markdown

Find out how to load two years of online store orders into the Lakehouse, concatenate them and clean them with a Custom action

Objective

This guide walks you through loading two years of orders from an online store (about 1 million order lines) into the Lakehouse, concatenating them into a single table and cleaning them with a Custom action. You upload the files with Connectors, create the tables in Lakehouse Manager, then concatenate and clean the orders with Data Processing Engine.

By the end you will have the table online_retail_ii_clean, ready to query from Apache Superset. The second part of the guide, Build a sales dashboard for an online store in Superset, turns it into a sales dashboard.

Requirements

To follow this guide you need:

  • A Data Platform project. This guide uses a project named ecommerce-sales.
  • The orders of the store and the cleaning script of the Custom action:
TypeName
Orders, December 2009 to December 2011Online Retail II, UCI Machine Learning Repository
Cleaning Python scriptonline_retail_cleaning.py

The UCI publishes the orders as one Excel workbook, online_retail_II.xlsx, with one sheet per year. Before Step 1, save each sheet as its own file:

SheetFile to create
Year 2009-2010online_retail_II_200910.xlsx
Year 2010-2011online_retail_II_201011.xlsx
Info

About the data: Online Retail II, UCI Machine Learning Repository, is licensed under CC BY 4.0 (DOI 10.24432/C5CG6D).

We recommend completing the Getting Started guides first. This guide assumes you are comfortable with the main components of Data Platform.

What you will build

The two parts of this guide end with this dashboard in Superset:

The finished Online store sales dashboard in Superset, with the key figures row and the Customers tab open
StageComponentResult
1. Upload the filesFile Upload sourceA source holding the two files
2. Analyse the filesAnalyzerDetected attributes and types
3. Create the tablesLakehouse Manager tablesOne table per year, one table for all orders
4. Concatenate the yearsLoad actions and a workflow1,067,371 order lines in online_retail_ii
5. Clean the ordersCustom action1,021,128 clean order lines in online_retail_ii_clean
6. Connect SupersetTrino consumer and Apache SupersetA Superset dataset on the clean table

Instructions

Step 1: Upload the files

  1. Open Connectors > Sources and create a new source of type File Upload.
  2. Name it online_retail_ii.
  3. Drop online_retail_II_200910.xlsx and online_retail_II_201011.xlsx in the Files area.
  4. Click Create.
The File Upload source named online_retail_ii with the two yearly Excel files added

Step 2: Analyse the files

  1. Open Connectors > Analyzer.
  2. Select the source online_retail_ii, then the file online_retail_II_200910.xlsx.
  3. Click Extract metadata.
  4. Do the same for online_retail_II_201011.xlsx.

The Analyzer detects 8 attributes: invoice, stockcode, description, quantity, invoicedate, price, customer_id and country. Check that invoice and stockcode are detected as String: invoice numbers such as C489449 and product codes such as 85123A are not numbers.

The Analyzer showing the attributes detected in online_retail_II_200910.xlsx

Step 3: Create the tables

Create one table per year

  1. Open Lakehouse Manager > Tables.

  2. Click New table > Create from a Connectors source.

    The New table menu in Lakehouse Manager with the Create from a Connectors source option
  3. Select the file online_retail_II_200910.xlsx from the source online_retail_ii, then click Next.

    Selection of the file online_retail_II_200910.xlsx from the source online_retail_ii
  4. Keep the default settings and click Create. The table is named online_retail_ii_200910, in the dataset default_dataset.

    The default table settings, with the name online_retail_ii_200910 and the three automatic options turned on
  5. Repeat with online_retail_II_201011.xlsx. The table is named online_retail_ii_201011.

Both tables appear with 8 attributes and about 525k and 542k rows.

The two yearly tables listed in Lakehouse Manager with their row counts

Create the table for all orders

  1. Duplicate the table online_retail_ii_200910. Hover over its row and click the Duplicate icon.

    The Duplicate icon on the row of the table online_retail_ii_200910 in Lakehouse Manager
  2. Name the new table online_retail_ii, in the dataset default_dataset, and click Create.

  3. Build the table.

The table has the same 8 attributes, and no rows yet.

The Create new empty table dialog with the name online_retail_ii and the dataset default_dataset

Step 4: Concatenate the two years

Create the Load actions

  1. Open Data Processing Engine > Actions and click New action.

  2. Search for load, select the Load action and click Select.

    The Load action selected in the list of action types
  3. Fill in the action:

    SettingValue
    Source tableonline_retail_II_200910.xlsx from online_retail_ii
    Destinationonline_retail_ii from default_dataset
    Attributeseach source attribute mapped to the destination attribute of the same name
  4. Click Create.

    The Load action settings mapping online_retail_II_200910.xlsx to the table online_retail_ii
  5. Create a second Load action, with online_retail_II_201011.xlsx as source and the same destination.

The list of actions shows your two Load actions, next to the two actions generated automatically when you created the yearly tables.

The list of actions with the two new Load actions and the two generated ones

Run both actions with a workflow

  1. In Data Processing Engine > Workflows, click New workflow.
  2. Name it Concat.
  3. In Stage 1, add your two Load actions.
  4. Click Create, then run the workflow.
The Concat workflow with the two Load actions in Stage 1, after a successful run

The workflow takes a couple of minutes. When its status turns green, open Lakehouse Manager > Tables: online_retail_ii holds the rows of both yearly tables, 1,067,371 rows.

Warning

Run the Concat workflow once. Running it again may add the same order lines a second time. After each run, check that online_retail_ii holds 1,067,371 rows.

To run the workflow again, you can create a Delete action that empties online_retail_ii, and run it before the workflow.

Step 5: Clean the orders

Create the clean table

  1. In Lakehouse Manager > Tables, duplicate online_retail_ii.
  2. Name the new table online_retail_ii_clean and build it.

You now have 4 tables. online_retail_ii_clean has the same 8 attributes and no rows yet.

The four tables of the guide listed in Lakehouse Manager

Create the cleaning action

  1. In Data Processing Engine > Actions, click New action.

  2. Search for custom, select the Custom action and click Select.

    The Custom action selected in the list of action types
  3. Fill in the action:

    SettingValue
    Action nameonline_retail_cleaning
    Function nameonline_retail_cleaning
    Development languagePython 3.11
    Python requirementspandas
    Fileupload online_retail_cleaning.py
  4. Click Create, then run the action.

The Custom action online_retail_cleaning with its function name, language, requirements and uploaded file
Info

Note: the function name is the entry point of the script and must be online_retail_cleaning. The other functions of the file are helpers: setting one of them as the function name returns 'Event' object is not subscriptable.

The action reads online_retail_ii, applies the cleaning rules and writes the result to online_retail_ii_clean. Open its logs: each rule reports how many rows it affects, and the last line gives the number of rows written to online_retail_ii_clean: 1,021,128 rows.

RuleA row is removed when
1. Exact duplicatesit is identical to another row on the 8 columns
2. Invalid invoice numberthe invoice is not 6 digits, with an optional C
3. Invalid stock codethe stock code is not 5 digits, with optional letters
4. Missing descriptionthe description is empty
5. Inconsistent quantitya sale is not positive, or a cancellation is not negative
6. Zero or negative pricethe price is not strictly positive
7. Missing invoice datethe date is empty

A final step, 8. Harmonized descriptions, gives each stock code its most frequent description, so a product never shows under two names.

Create an action to empty the clean table

The cleaning action adds rows to online_retail_ii_clean. Before running it again, empty the table with a Delete action, as for online_retail_ii before running the Concat workflow again.

  1. Click New action, search for delete, select the Delete action and click Select.
  2. In Table list, move online_retail_ii_clean to Table to empty.
  3. Click Create.
The Delete action with online_retail_ii_clean in the Table to empty list

To clean the data again, run this Delete action first, then online_retail_cleaning.

Step 6: Connect Superset

All the data is now ready in the Lakehouse. To analyse it, create an Apache Superset application:

  1. Create a Trino connection by following the Generate a Trino connection string for external tools guide.
  2. Create the application and connect it to Trino by following Steps 1 to 3 of the Deploying Apache Superset on OVHcloud Data Platform guide.

Create the dataset in Superset

  1. In Superset, open Datasets and click + Dataset.
  2. Select the database connection you created, named Trino DP in this guide, then the schema default_dataset and the table online_retail_ii_clean.
  3. Check the columns, then click Create and explore dataset.
The Superset dataset form with the database, the schema default_dataset and the table online_retail_ii_clean selected

Every chart of the dashboard then starts from Charts > + Chart: choose the dataset online_retail_ii_clean, then the chart type.

The Superset chart creation screen with the dataset online_retail_ii_clean selected

Continue with Build a sales dashboard for an online store in Superset.

Good to know

  • You can connect a real store. This guide uses a public dataset, uploaded as files. To analyse the orders of your own store, create a Shopify or Stripe source instead of the File Upload source: in Connectors > Sources, both appear in the New source window. The tables then follow the attributes of that source, and the cleaning script must be adapted to them.
The New source window with the Stripe and Shopify connectors

What you have built

You have a raw table with every order line of the store, a clean table that follows the UCI description of the variables, and a Superset dataset on top of it.

The next part, Build a sales dashboard for an online store in Superset, turns the clean table into a dashboard: key figures, revenue over time, best-selling products, sales by country and customer loyalty.

Go further

For training or technical assistance implementing our solutions, contact your sales representative or visit our Professional Services page to request a quote and have your project analysed by our experts.

Ask questions, give your feedback and interact directly with the team building the Data Platform on the dedicated Discord channel.

If you need support with your OVHcloud services, create a request in our Help Centre.

Join our community of users.

¿Le ha resultado útil esta página?