title | icon | description |
---|---|---|
table |
table |
Display data in an interactive table format |
table(data: pd.DataFrame, title: Optional[str] = None, limit: Optional[int] = None) -> Dict
The table
function provides an easy way to display datasets in an interactive table format, making it simple to explore and understand your data.
data
(Pandas DataFrame): The dataset you want to display. Must be a Pandas DataFrame or a list of dictionaries.title
(str, optional): An optional title to display above the table.limit
(int, optional): Maximum number of rows to display. If not specified, shows all rows.
Dict
containing the table component metadata and processed data.
Here's an example of how to use the table
function:
from preswald import table
# Example DataFrame
import pandas as pd
data = {
"Name": ["Alice", "Bob", "Charlie"],
"Age": [25, 30, 35],
"City": ["New York", "Los Angeles", "Chicago"]
}
df = pd.DataFrame(data)
# Display the dataset with a title
table(df, title="Employee Data")
# Display just the data
table(df)
- Automatic Data Processing: Handles various data types including timestamps, numpy arrays, and nested structures
- Interactive Display: Renders data in a format optimized for exploration and analysis
- Error Handling: Gracefully handles edge cases and provides clear error messages
- Flexible Input: Accepts both Pandas DataFrames and lists of dictionaries
The table component automatically handles various data types:
- Basic types (strings, numbers, booleans)
- Timestamps and datetime objects
- Numpy arrays and numeric types
- Missing values (None, NaN)
- Nested data structures (lists, arrays)
-
Large Datasets: For large datasets, consider limiting the rows before display:
table(df, title="First 100 Rows", limit=100)
-
Column Selection: Select relevant columns to improve readability:
table(df[['Name', 'Age', 'City']])
-
Data Preprocessing: Clean and format data before display:
# Round numeric columns df_clean = df.round(2) table(df_clean)