It’s Ti-i-ime to Visualize the Christmas Dataset with Python and Flexmonster Pivot Table!

It’s Ti-i-ime to Visualize the Christmas Dataset with Python and Flexmonster Pivot Table!

As the season of giving and shopping approaches, Christmas sales and trends become even more fascinating. This magical time is about traditions and discovery—finding the perfect gift, uncovering unique trends, or researching new tools to bring ideas to life.

While exploring an intriguing Christmas Sales and Trends dataset on Kaggle, I needed a powerful, interactive, and user-friendly platform to visualize its insights. That’s where Jupyter Lab proved invaluable. Paired with Flexmonster, it offers the perfect combination for creating insightful visualizations.

In this tutorial, I’ll show you how to use these tools to explore the dataset, uncovering classic holiday favorites and delightful hidden gems that make the season special.
And keep in mind that you can always refer to my GitHub repository for the complete code. 👩‍💻

However, before diving into coding, let me explain why I chose such a stack of technologies to work with.

Why Did I Choose Jupyter Lab as a Data Visualization Platform?

Jupyter Lab is a go-to tool for data visualization using Python. Its standout feature is step-by-step execution, allowing you to visualize data on the fly and adjust as needed. Moreover, Jupyter Lab supports a variety of libraries, such as Pandas for data manipulation, Matplotlib, and Seaborn for static plots, Plotly for interactive visualizations, and many more. This makes creating everything from basic charts to complex, interactive dashboards easy.

Moreover, Jupyter Lab provides a user-friendly interface, which makes it easy for analysts and developers of all levels to bring data to life in a visually engaging way.

Why Did I Choose Flexmonster as a Data Visualization Tool?

Flexmonster is a powerful JavaScript pivot table component designed to analyze complex datasets efficiently. It excels at handling large amounts of data with remarkable speed, ensuring smooth performance even when working with months of detailed sales and customer data. Additionally, since Flexmonster Pivot Table & Charts is highly adaptable to diverse workflows, you can seamlessly integrate it with Jupyter and other popular technologies.

What also appealed to me is how well-documented Flexmonster is. The documentation is straightforward and comprehensive and provides excellent guidance for users at all levels. You'll notice me frequently referencing it throughout this article for additional clarity.

How to Get Jupyter Lab

To install Jupyter Lab and/or Notebook on your machine, follow this simple guide from the official documentation. I followed the instructions and got it with the help of pip, the recommended installation tool for Python.

To get the Jupyter Lab, you have to type the following command in your Command Prompt:

pip install jupyterlab

For macOS:

pip3 install jupyterlab

Once Jupyter Lab is installed, you can run it using a universal command for macOS, Windows, and Linux:

jupyter lab

After this, your browser will automatically redirect you to Jupyter Lab.

How to Get Flexmonster

First and foremost, you have to install Flexmonster CLI. Do this by executing the following command in your Terminal / Command Prompt:

npm install -g flexmonster-cli

Now, run Jupyter Lab, and let’s start coding!

How to Visualize Data in Jupyter Lab

Let’s start with some imports, shall we?

from IPython.core.display import HTML  # A module to render HTML content directly in the notebook, useful for displaying styled tables or visual elements

import os  # This module enables interaction with the file system, such as managing files or directories

import pandas as pd  # Pandas library is for reading, manipulating, and analyzing tabular data. We will install it soon in this section

import json  # JSON module helps handle structured data in JSON format.

import kagglehub  # This library allows us to download datasets from Kaggle and manage them. We will also install it later in this section

As I mentioned earlier, you need to install the pandas library. I suggest using pip (pip3) by typing this into the Command prompt:

pip install pandas

Or this, in case you are using macOS:

pip3 install pandas

You also need to create an account on Kaggle and follow the tutorial to set up your Kaggle API Key.

Then you have to install kagglehub on your machine. To achieve this, type the following command in your Command Prompt:

pip install kagglehub

For macOS users:

pip3 install kagglehub

Once you have completed all the prerequisites, let’s write some code. We will start with fetching Christmas Sales and Trends data from Kaggle:

# Login to Kaggle
kagglehub.login()

path = kagglehub.dataset_download("ibikunlegabriel/christmas-sales-and-trends")

dataset_file = os.path.join(path, "Christmas Sales and Trends.csv")

data = pd.read_csv(dataset_file)

Next, I configured the ReportObject.

Note that with Flexmonster, we are using the trial key, so we have a watermark. If you are considering using this JavaScript library for your other projects, I advise you to choose the license that best suits your needs.

# Flexmonster setup

json_data = data.to_dict(orient="records")

flexmonster_configs = {
    "container": "pivotContainer",
    "componentFolder": "https://cdn.flexmonster.com/",
    "toolbar": True,
    "report": {
        "dataSource": {
            "type": "json",
            "data": json_data
        },
        "formats": [
            {
                "name": "",
                "decimalPlaces": 0,
            }
        ],
        "slice": {
            "rows": [
                {"uniqueName": "Category"},
            ],
            "columns": [
                {"uniqueName": "Gender"}
            ],
            "measures": [
                {
                    "uniqueName": "TotalPrice",
                },
                {
                    "uniqueName": "Quantity",
                },
            ]
        },
        "options": {
            "grid": {
                "showTotals": "off",
                "showGrandTotals": "off",
                "layoutForm": "classic",
            }
        }
    }
}

Last but not least, we need to set up the function to render Flexmonster:

def pivot(flexmonster_config):
    config_json = json.dumps(flexmonster_config)
    code = f'''
    <link rel="stylesheet" type="text/css" href="https://cdn.flexmonster.com/theme/accessible/flexmonster.min.css"/>
    <h1>Flexmonster integration with Jupyter Lab</h1>
    <!-- This is the div where Flexmonster is initialized -->
    <div id="pivotContainer" style="height: 600px;"></div>
    <script src="https://cdn.flexmonster.com/flexmonster.js"></script>
    <script>
    new Flexmonster({config_json});
    </script>
    '''
    return HTML(code)

# Display the pivot table
pivot(flexmonster_configs)

Among all the categories, I chose to highlight the “Decorations” one, as it's where I plan to pick a gift. I added a small snowflake to make it easy to spot. To implement this, you can create a simple loop:

for record in json_data:
    if record["Category"] == "Decorations":
        record["Category"] = "Decorations ❄️"

And there you have it!

Press the “Run All” button and look for the perfect gift for your loved ones!

Flexmonster Pivot visualization of the most popular Christmas presents by gender

While on the subject, I found that built-in Flexmonster charts can make the analysis even more dynamic. To choose the type you prefer—column, pie, scatter, or another—press the “Charts” button on the Toolbar.

Moreover, Flexmonster can integrate with any charting library, allowing you to use the charts you like to create the visualizations you want.

Below, you can see all available Flexmonster Charts:

Presentation of all available Flexmonster Charts

I hope you found this quick and simple data visualization tutorial both informative and inspiring. Together, we explored how to leverage Python, Jupyter, and Flexmonster to uncover fascinating trends in Christmas gift shopping.

As for me, I’ve decided to pick up some festive decorations and holiday outfits as presents—what about you? What trends are sparking your interest this season? Share your thoughts in the comments!

Wishing you a joyful holiday season filled with creativity and cheer. Happy holidays and happy coding! 🎄🎁✨