Runnable examples for the frozen Gradio Lite 5.45.0 browser runtime.
Filter an editable Pandas data frame with a Gradio dropdown.
This coding playground passes an editable table to Pandas and filters it by the selected gender value. Click Run, choose M, F, or O, then submit to return matching rows.
Code
import gradio as grimport pandas as pd# Create sample datasample_data = pd.DataFrame([ ["John", 25, "M"], ["Sarah", 30, "F"], ["Alex", 35, "O"], ["Emma", 28, "F"], ["Michael", 42, "M"]], columns=["name", "age", "gender"])def filter_records(records, gender):return records[records["gender"] == gender]demo = gr.Interface( filter_records, [ gr.Dataframe( headers=["name", "age", "gender"], datatype=["str", "number", "str"], value=sample_data.values.tolist(), row_count=5, col_count=(3, "fixed"), interactive=True ), gr.Dropdown(["M", "F", "O"], value="M"), ],"dataframe", description="Choose M, F, or O to filter the records.", flagging_mode="never",)demo.launch()
import gradio as gr
import pandas as pd
# Create sample data
sample_data = pd.DataFrame([
["John", 25, "M"],
["Sarah", 30, "F"],
["Alex", 35, "O"],
["Emma", 28, "F"],
["Michael", 42, "M"]
], columns=["name", "age", "gender"])
def filter_records(records, gender):
return records[records["gender"] == gender]
demo = gr.Interface(
filter_records,
[
gr.Dataframe(
headers=["name", "age", "gender"],
datatype=["str", "number", "str"],
value=sample_data.values.tolist(),
row_count=5,
col_count=(3, "fixed"),
interactive=True
),
gr.Dropdown(["M", "F", "O"], value="M"),
],
"dataframe",
description="Choose M, F, or O to filter the records.",
flagging_mode="never",
)
demo.launch()