Skip to main content

Component | DataFrame

Render a pandas DataFrame.

info

This is a Python SDK only component.

df = pd.DataFrame({
'name': ['John', 'Jane', 'Bob'],
'age': [30, 25, 35],
'city': ['New York', 'London', 'San Francisco']
})

ui.dataframe(
"dataframe-key",
df,
label="Users",
)

This component is a light wrapper around the Table component. The only difference is that it accepts a pandas DataFrame as input instead of a list of dictionaries.

Under the hood, Compose will convert the DataFrame into a list of dictionaries and then render a table. That code is pasted below for reference.

# Replace empty values in the dataframe
df = df.replace({
None: '',
pandas.NA: '',
float('nan'): ''
})

# Create the "columns" array
columns = [
{"key": col, "label": col} for col in df.columns
]

# Create the list of dictionaries.
table_data = df.to_dict(orient="records")