A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
marimo-snippets on dataframe page (#4638)
vincent d warmerdamed9f0af7701e
diff --git a/docs/guides/working_with_data/dataframes.md b/docs/guides/working_with_data/dataframes.mdindex 69a2dd6dab..9e24a59310 100644--- a/docs/guides/working_with_data/dataframes.md+++ b/docs/guides/working_with_data/dataframes.md@@ -46,18 +46,42 @@ dfimport polars as pldf = pl.read_json(- "https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json"+"https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json")df```///+/// tab | live example++/// marimo-embed+ size: large++```python+def __():+ import pandas as pd++ pd.read_json(+ "https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json"+ )+ return+```++///++///++To opt out of the rich dataframe viewer, use [`mo.plain`][marimo.plain]:/// tab | pandas```python+import pandas as pd+import marimo as mo+df = pd.read_json("https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json")@@ -69,6 +93,9 @@ mo.plain(df)/// tab | polars```python+import polars as pl+import marimo as mo+df = pl.read_json("https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json")@@ -77,6 +104,27 @@ mo.plain(df)///+/// tab | live example++/// marimo-embed+ size: large++```python+def __():+ import pandas as pd++ df = pd.read_json(+ "https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json"+ )+ mo.plain(df)+ return+```++///++///+## Transforming dataframes### No-code transformations@@ -94,6 +142,15 @@ notebook.</figure></div>+The transformations you apply will turn into code which is accessible via the "code" tab.++<div align="center">+<figure>+<img src="/_static/docs-dataframe-transform-code.png"/>+<figcaption>Copy the code of the transformation</figcaption>+</figure>+</div>+/// tab | pandas```python@@ -114,6 +171,7 @@ transformed_df.value///+/// tab | polars```python@@ -134,12 +192,33 @@ transformed_df.value///-<div align="center">-<figure>-<img src="/_static/docs-dataframe-transform-code.png"/>-<figcaption>Copy the code of the transformation</figcaption>-</figure>-</div>++/// tab | live example++/// marimo-embed+ size: large++```python+def __():+ import pandas as pd++ df = pd.DataFrame({"person": ["Alice", "Bob", "Charlie"], "age": [20, 30, 40]})+ transformed_df = mo.ui.dataframe(df)+ transformed_df+ return++def __():+ transformed_df.value++ return+```++///++///+### Custom filters@@ -169,6 +248,7 @@ mo.ui.table(filtered_df)/// tab | polars```python+# Cell 1import marimo as moimport polars as pl@@ -192,6 +272,37 @@ mo.ui.table(filtered_df)///+/// tab | live example+++/// marimo-embed+ size: large++```python+def __():+ import pandas as pd++ df = pd.DataFrame({"person": ["Alice", "Bob", "Charlie"], "age": [20, 30, 40]})+ return++def __():+ age_filter = mo.ui.slider(start=0, stop=100, value=50, label="Max age")+ age_filter+ return++def __():+ filtered_df = df[df["age"] < age_filter.value]+ mo.ui.table(filtered_df)+ return+```++///++///+## Select dataframe rows {#selecting-dataframes}Display dataframes as interactive, [selectable charts](plotting.md) using@@ -247,6 +358,30 @@ table.value///++/// tab | live example++/// marimo-embed+ size: large++```python+def __():+ import pandas as pd++ df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})+ table = mo.ui.table(df, selection="multi")+ table+ return++def __():+ table.value+ return+```++///+## Dataframe panelsDataframe outputs in marimo come with several panels to help you visualize, explore, and page through your data interactively. These panels are accessible via toggles at the bottom-left of a dataframe output. If you need further control, after opening a panel you can@@ -296,6 +431,7 @@ altair.data_transformers.enable("vegafusion")The chart builder toggle lets you rapidly develop charts using a GUI, while also generating Python code to insert in your notebook. Refer to the [chart builder guide](plotting.md#chart-builder) for more details.+## Example notebookFor a comprehensive example of using Polars with marimo, check out our [Polars example notebook](https://github.com/marimo-team/marimo/blob/main/examples/third_party/polars/polars_example.py).