Skills Advisor | Data Visualization

Data Preparation for Horizon Chart

Learn how to structure your data for a horizon chart by aggregating, pivoting, normalizing, and ensuring the data range. Includes a Python code example using pandas for guidance.


Empty image or helper icon

Prompt

how to shape data for a horizon chart provide sample dataset

Answer

Data Visualization Advice: Shaping Data for Horizon Chart

To create a horizon chart, you typically need to structure your data in a specific format. Here's a suggested approach along with a sample dataset:

Sample Dataset:

Consider a dataset with columns:

  • Date: Time dimension
  • Category: Categorical data for grouping
  • Value: Numeric data for plotting

Data Shaping Steps:

  1. Aggregate Data: If your dataset is at a detailed level, aggregate it to the desired level for the horizon chart.
  2. Pivot Data: Reshape the data into a wide format with categories as columns and dates as rows. This can be achieved using tools like pivot_table in Python's pandas library or similar functions in other tools.
  3. Normalize Data: Normalize the values within each category to a common scale for effective visualization. This can involve techniques like min-max scaling or z-score normalization.
  4. Ensure Data Range: Ensure that your data values fall within a specific range suitable for the horizon chart to display variations clearly.

Code Example (Python - Using pandas):

import pandas as pd

# Sample data
data = {'Date': ['2021-01-01', '2021-01-02', '2021-01-03'],
        'Category': ['A', 'B', 'A'],
        'Value': [100, 150, 120]}

df = pd.DataFrame(data)

# Pivot data
pivot_df = df.pivot_table(index='Date', columns='Category', values='Value').reset_index()

# Normalize data
pivot_df.iloc[:, 1:] = (pivot_df.iloc[:, 1:] - pivot_df.iloc[:, 1:].min()) / (pivot_df.iloc[:, 1:].max() - pivot_df.iloc[:, 1:].min())

print(pivot_df)

By following these steps and shaping your data accordingly, you can prepare it for visualization using a horizon chart effectively.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

Learn how to structure your data for a horizon chart by aggregating, pivoting, normalizing, and ensuring the data range. Includes a Python code example using pandas for guidance.