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: pd.DataFrame, on_change: Callable[[pd.DataFrame], None] | None = None, page_size: int | None = 5)#
Run transformations on a DataFrame or series. Currently only Pandas DataFrames are supported.
For Polars DataFrames, you can convert to a Pandas DataFrame. However the returned DataFrame will still be a Pandas DataFrame, so you will need to convert back to a Polars DataFrame if you want.
Example.
dataframe = mo.ui.dataframe(data)
dataframe = mo.ui.dataframe(polars_df.to_pandas())
Attributes.
value
: the transformed DataFrame or series
Initialization Args.
df
: the DataFrame or series to transformpage_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.
Inherited from
UIElement
form
([label, bordered, loading, ...])Create a submittable form out of this
UIElement
.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:
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.