Skip to content

Tables & Data

Table

Table blocks store the contents of a DataFrame as a HTML table whose style can be customised using pandas' Styler API.

Tip

Table is the best option for displaying multidimensional DataFrames, as DataTable will flatten your data.

Parameters:

Name Type Description Default
data Union[DataFrame, Styler]

The pandas Styler instance or dataframe to generate the table from

required
caption Optional[str]

A caption to display below the table (optional)

None
name BlockId

A unique name for the block to reference when adding text or embedding (optional)

None
label str

A label used when displaying the block (optional)

None

Simple Table from DataFrame

import pandas as pd
import numpy as np

df = pd.DataFrame(
    {
        "A": np.random.normal(-1, 1, 5),
        "B": np.random.normal(1, 2, 5),
    }
)

dp.Table(df)

Styled Table from DataFrame

If your DataFrame includes DataFrame Styles, these will be included in your app. DataFrame styles allow you create custom formatted tables; for instance, to show trends, highlight cells, add bar charts, or display correlations.

import pandas as pd
import numpy as np

df = pd.DataFrame({"A": np.linspace(1, 10, 10)})
df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns=list("BCDE"))], axis=1)

dp.Table(df.style.background_gradient(cmap="viridis"))

DataTable

The DataTable block takes a pandas DataFrame and renders an interactive, sortable, searchable table in your app, along with advanced analysis options such as exploring data through SandDance.

It supports large datasets and viewers can also download the table from the website as a CSV or Excel file.

Tip

Table is the best option for displaying multidimensional DataFrames, as DataTable will flatten your data.

Parameters:

Name Type Description Default
df DataFrame

The pandas dataframe to attach to the report

required
caption Optional[str]

A caption to display below the plot (optional)

None
name BlockId

A unique name for the block to reference when adding text or embedding (optional)

None
label str

A label used when displaying the block (optional)

None

Simple DataTable from DataFrame

import pandas as pd
import numpy as np

df = pd.DataFrame(
    {
        "A": np.random.normal(-1, 1, 5000),
        "B": np.random.normal(1, 2, 5000),
    }
)

dp.DataTable(df)

Running Queries on DataTable

You can run SQL queries on your datatable if you need more advanced filtering & calculations. In the previous example, if we wanted to show only the rows which had a value A > 0.5, we would write the following (note that $table is the builtin table name and cannot be changed):

SELECT * FROM $table
WHERE A > 0.5

BigNumber

A single number or change can often be the most important thing in an app.

The BigNumberblock allows you to present KPIs, changes, and statistics in a friendly way to your viewers.

You can optionally set intent, and pass in numbers or text.

Parameters:

Name Type Description Default
heading str

A title that gives context to the displayed number

required
value NumberValue

The value of the number

required
prev_value Optional[NumberValue]

The previous value to display as comparison (optional)

None
change Optional[NumberValue]

The amount changed between the value and previous value (optional)

None
is_positive_intent Optional[bool]

Displays the change on a green background if True, and red otherwise. Follows is_upward_change if not set (optional)

None
is_upward_change Optional[bool]

Whether the change is upward or downward (required when change is set)

None
name BlockId

A unique name for the block to reference when adding text or embedding (optional)

None
label str

A label used when displaying the block (optional)

None

Simple BigNumber

dp.BigNumber(heading="Simple Statistic", value=100)

BigNumber with change indicators

dp.Group(
    dp.BigNumber(
        heading="Percentage points",
        value="84%",
        change="2%",
        is_upward_change=True,
    ),
    dp.BigNumber(
        heading="Percentage points",
        value="84%",
        change="2%",
        is_upward_change=False,
    ),
    dp.BigNumber(
        heading="Points",
        value="1234",
        change="200",
        is_upward_change=True,
    ),
    dp.BigNumber(
        heading="Points",
        value="1234",
        change="200",
        is_upward_change=False,
    ),
    columns=2,
)