DataFrame - marimo (original) (raw)
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 or Polars Required
In order to use the dataframe UI element, you must have the pandas or polars package installed. You can install it with pip install pandas or pip install polars.
Supported transforms are:
- Filter Rows
- Select Columns
- Rename Column
- Column Conversion
- Sort Column
- Group By
- Aggregate
- Sample Rows
- Shuffle Rows
- Explode Columns
- Expand Dict
`` marimo.ui.dataframe ¶
[](#%5F%5Fcodelineno-0-1)dataframe( [](#%5F%5Fcodelineno-0-2) df: DataFrameType, [](#%5F%5Fcodelineno-0-3) on_change: Callable[[DataFrameType], None] [](#%5F%5Fcodelineno-0-4) | None = None, [](#%5F%5Fcodelineno-0-5) page_size: int | None = 5, [](#%5F%5Fcodelineno-0-6) limit: int | None = None, [](#%5F%5Fcodelineno-0-7) show_download: bool = True, [](#%5F%5Fcodelineno-0-8))
Bases: UIElement[dict[str, Any], DataFrameType]
Run transformations on a DataFrame or series.
Currently supports Pandas, Polars, Ibis, Pyarrow, and DuckDB.
Examples:
[](#%5F%5Fcodelineno-0-1)dataframe = mo.ui.dataframe(data)
| ATTRIBUTE | DESCRIPTION |
|---|---|
| value | The transformed DataFrame or series. TYPE: DataFrameType |
| PARAMETER | DESCRIPTION |
|---|---|
| df | The DataFrame or series to transform. TYPE: DataFrameType |
| page_size | The number of rows to show in the table. Defaults to 5. TYPE: int | None DEFAULT: 5 |
| limit | The number of items to load into memory, in case the data is remote and lazily fetched. This is likely true for SQL-backed dataframes via Ibis. TYPE: int | None DEFAULT: None |
| show_download | Whether to show the download button. Defaults to True. TYPE: bool DEFAULT: True |
| on_change | Optional callback to run when this element's value changes. TYPE: Callable[[DataFrameType], None] | None DEFAULT: None |
`` text property ¶
A string of HTML representing this element.
`` value property writable ¶
The element's current value.
`` batch ¶
[](#%5F%5Fcodelineno-0-1)batch(**elements: UIElement[JSONType, object]) -> [batch](../batch/#marimo.ui.batch " marimo.ui.batch (marimo._plugins.ui._impl.batch.batch)")
Convert an HTML object with templated text into a UI element.
This method lets you create custom UI elements that are represented by arbitrary HTML.
Example
[](#%5F%5Fcodelineno-0-1)user_info = mo.md( [](#%5F%5Fcodelineno-0-2) ''' [](#%5F%5Fcodelineno-0-3) - What's your name?: {name} [](#%5F%5Fcodelineno-0-4) - When were you born?: {birthday} [](#%5F%5Fcodelineno-0-5) ''' [](#%5F%5Fcodelineno-0-6)).batch(name=mo.ui.text(), birthday=mo.ui.date())
In this example, user_info is a UI Element whose output is markdown and whose value is a dict with keys 'name' and 'birthday' (and values equal to the values of their corresponding elements).
| PARAMETER | DESCRIPTION |
|---|---|
| elements | the UI elements to interpolate into the HTML template. TYPE: UIElement[JSONType, object] DEFAULT: {} |
`` callout ¶
`callout( kind: Literal[ "neutral", "danger", "warn", "success", "info" ] = "neutral" ) -> [Html](../../html/#marimo.Html " marimo.Html
dataclass(marimo._output.hypertext.Html)") `
Create a callout containing this HTML element.
A callout wraps your HTML element in a raised box, emphasizing its importance. You can style the callout for different situations with thekind argument.
Examples:
[](#%5F%5Fcodelineno-0-1)mo.md("Hooray, you did it!").callout(kind="success")
[](#%5F%5Fcodelineno-1-1)mo.md("It's dangerous to go alone!").callout(kind="warn")
`` center ¶
Center an item.
Example
[](#%5F%5Fcodelineno-0-1)mo.md("# Hello, world").center()
| RETURNS | DESCRIPTION |
|---|---|
| Html | An Html object. |
`` form ¶
[](#%5F%5Fcodelineno-0-1)form( [](#%5F%5Fcodelineno-0-2) label: str = "", [](#%5F%5Fcodelineno-0-3) *, [](#%5F%5Fcodelineno-0-4) bordered: bool = True, [](#%5F%5Fcodelineno-0-5) loading: bool = False, [](#%5F%5Fcodelineno-0-6) submit_button_label: str = "Submit", [](#%5F%5Fcodelineno-0-7) submit_button_tooltip: str | None = None, [](#%5F%5Fcodelineno-0-8) submit_button_disabled: bool = False, [](#%5F%5Fcodelineno-0-9) clear_on_submit: bool = False, [](#%5F%5Fcodelineno-0-10) show_clear_button: bool = False, [](#%5F%5Fcodelineno-0-11) clear_button_label: str = "Clear", [](#%5F%5Fcodelineno-0-12) clear_button_tooltip: str | None = None, [](#%5F%5Fcodelineno-0-13) validate: Callable[[Optional[JSONType]], str | None] [](#%5F%5Fcodelineno-0-14) | None = None, [](#%5F%5Fcodelineno-0-15) on_change: Callable[[Optional[T]], None] | None = None [](#%5F%5Fcodelineno-0-16)) -> [form](../form/#marimo.ui.form " marimo.ui.form (marimo._plugins.ui._impl.input.form)")[S, T]
Create a submittable form out of this UIElement.
Creates a form that gates submission of a UIElement's value until a submit button is clicked. The form's value is the value of the underlying element from the last submission.
Examples:
Convert any UIElement into a form:
[](#%5F%5Fcodelineno-0-1)prompt = mo.ui.text_area().form()
Combine with HTML.batch to create a form made out of multiple UIElements:
[](#%5F%5Fcodelineno-1-1)form = ( [](#%5F%5Fcodelineno-1-2) mo.ui.md( [](#%5F%5Fcodelineno-1-3) ''' [](#%5F%5Fcodelineno-1-4) **Enter your prompt.** [](#%5F%5Fcodelineno-1-5) [](#%5F%5Fcodelineno-1-6) {prompt} [](#%5F%5Fcodelineno-1-7) [](#%5F%5Fcodelineno-1-8) **Choose a random seed.** [](#%5F%5Fcodelineno-1-9) [](#%5F%5Fcodelineno-1-10) {seed} [](#%5F%5Fcodelineno-1-11) ''' [](#%5F%5Fcodelineno-1-12) ) [](#%5F%5Fcodelineno-1-13) .batch( [](#%5F%5Fcodelineno-1-14) prompt=mo.ui.text_area(), [](#%5F%5Fcodelineno-1-15) seed=mo.ui.number(), [](#%5F%5Fcodelineno-1-16) ) [](#%5F%5Fcodelineno-1-17) .form() [](#%5F%5Fcodelineno-1-18))
| PARAMETER | DESCRIPTION | |
|---|---|---|
| label | A text label for the form. TYPE: str DEFAULT: '' | |
| bordered | Whether the form should have a border. TYPE: bool DEFAULT: True | |
| loading | Whether the form should be in a loading state. TYPE: bool DEFAULT: False | |
| submit_button_label | The label of the submit button. TYPE: str DEFAULT: 'Submit' | |
| submit_button_tooltip | The tooltip of the submit button. TYPE: str | None DEFAULT: None | |
| submit_button_disabled | Whether the submit button should be disabled. TYPE: bool DEFAULT: False | |
| clear_on_submit | Whether the form should clear its contents after submitting. TYPE: bool DEFAULT: False | |
| show_clear_button | Whether the form should show a clear button. TYPE: bool DEFAULT: False | |
| clear_button_label | The label of the clear button. TYPE: str DEFAULT: 'Clear' | |
| clear_button_tooltip | The tooltip of the clear button. TYPE: str | None DEFAULT: None | |
| validate | A function that takes the form's value and returns an error message if invalid, or None if valid. TYPE: Callable[[Optional[JSONType]], str | None] | None DEFAULT: None |
| on_change | Optional callback to run when this element's value changes. Defaults to None. TYPE: Callable[[Optional[T]], None] | None DEFAULT: None |
`` from_args classmethod ¶
[](#%5F%5Fcodelineno-0-1)from_args( [](#%5F%5Fcodelineno-0-2) data: dict[str, int], [](#%5F%5Fcodelineno-0-3) args: InitializationArgs[S, T], [](#%5F%5Fcodelineno-0-4) memo: dict[int, Any] | None = None, [](#%5F%5Fcodelineno-0-5) basis: UIElement[S, T] | None = None, [](#%5F%5Fcodelineno-0-6)) -> UIElement[S, T]
`` left ¶
Left-justify.
Example
[](#%5F%5Fcodelineno-0-1)mo.md("# Hello, world").left()
| RETURNS | DESCRIPTION |
|---|---|
| Html | An Html object. |
`` right ¶
Right-justify.
Example
[](#%5F%5Fcodelineno-0-1)mo.md("# Hello, world").right()
| RETURNS | DESCRIPTION |
|---|---|
| Html | An Html object. |
`` style ¶
`style( style: dict[str, Any] | None = None, **kwargs: Any ) -> [Html](../../html/#marimo.Html " marimo.Html
dataclass(marimo._output.hypertext.Html)") `
Wrap an object in a styled container.
Example
[](#%5F%5Fcodelineno-0-1)mo.md("...").style({"max-height": "300px", "overflow": "auto"}) [](#%5F%5Fcodelineno-0-2)mo.md("...").style(max_height="300px", overflow="auto")
| PARAMETER | DESCRIPTION |
|---|---|
| style | an optional dict of CSS styles, keyed by property name TYPE: dict[str, Any] | None DEFAULT: None |
| **kwargs | CSS styles as keyword arguments TYPE: Any DEFAULT: {} |