Dataframe

The dataframe UI element outputs a visual editor to apply “transforms” to a dataframe, such as filtering rows, applying group-bys and aggregations, and more. The transformed dataframe is shown below the transform editor. The UI output also includes the generated Python used to generate the resulting dataframe, which you can copy paste into a cell. You can programmatically access the resulting dataframe by accessing the element’s .value attribute.

Pandas Required

In order to use the dataframe UI element, you must have the pandas package installed. You can install it with pip install pandas.

Supported transforms are:

  • Filter Rows

  • Rename Column

  • Column Conversion

  • Sort Column

  • Group By

  • Aggregate

class marimo.ui.dataframe(df: DataFrameType, on_change: Callable[[DataFrameType], None] | None = None, page_size: int | None = 5)

Run transformations on a DataFrame or series. Currently only Pandas or Polars DataFrames are supported.

Example.

dataframe = mo.ui.dataframe(data)

Attributes.

  • value: the transformed DataFrame or series

Initialization Args.

  • df: the DataFrame or series to transform

  • page_size: the number of rows to show in the table

Public methods

get_dataframe(_args)

get_column_values(args)

Get all the unique values in a column.

search(args)

Inherited from UIElement

form([label, bordered, loading, ...])

Create a submittable form out of this UIElement.

send_message(message, buffers)

Send a message to the element rendered on the frontend from the backend.

Inherited from Html

batch(**elements)

Convert an HTML object with templated text into a UI element.

center()

Center an item.

right()

Right-justify.

left()

Left-justify.

callout([kind])

Create a callout containing this HTML element.

style(style)

Wrap an object in a styled container.

Public Data Attributes:

DISPLAY_LIMIT

Inherited from UIElement

value

The element’s current value.

Inherited from Html

text

A string of HTML representing this element.


get_column_values(args: GetColumnValuesArgs) GetColumnValuesResponse

Get all the unique values in a column.