Skip to content

Latest commit

 

History

History
98 lines (79 loc) · 2.74 KB

Python_Explore_Dataset_with_Pivot_Table.md

File metadata and controls

98 lines (79 loc) · 2.74 KB



Template request | Bug report | Generate Data Product

Tags: #python #dataset #pivottable #dataexploration

Author: Florent Ravenel

Description: This notebook allows you to interactively explore and analyze a dataset using a pivot table. It uses the pivottablejs library to generate a dynamic pivot table in your web browser, giving you the ability to sort, filter, and aggregate data in real-time. This template provides a simple and intuitive way to explore and gain insights from your dataset, making it a valuable tool for data analysis and visualization.

References:

Input

Import libraries

import pandas as pd
try:
    from pivottablejs import pivot_ui
except:
    !pip install pivottablejs --user
    from pivottablejs import pivot_ui

Setup Variables

# Create a fake dataset
data = {
    "Month": [
        "January",
        "February",
        "March",
        "April",
        "May",
        "June",
        "July",
        "August",
        "September",
        "October",
        "November",
        "December",
    ]
    * 2,
    "Region": ["North"] * 12 + ["South"] * 12,
    "Sales": [
        11000,
        12000,
        13000,
        14000,
        15000,
        16000,
        17000,
        18000,
        19000,
        20000,
        21000,
        22000,
    ]
    + [
        10000,
        11000,
        12000,
        13000,
        14000,
        15000,
        16000,
        17000,
        18000,
        19000,
        20000,
        21000,
    ],
}

Model

Create DataFrame

df = pd.DataFrame(data)
df.head(12)

Output

Use the pivot_ui function to create a pivot table

# Use the pivot_ui function to create a pivot table
pivot_ui(df)