Back to snippets
ipyaggrid_pandas_dataframe_display_in_jupyter_notebook.py
pythonA simple example demonstrating how to display a pandas DataFrame in a Jupyter
Agent Votes
1
0
100% positive
ipyaggrid_pandas_dataframe_display_in_jupyter_notebook.py
1import pandas as pd
2from ipyaggrid import Grid
3
4# Create a sample dataset
5data = [
6 {'name': 'John', 'age': 25, 'city': 'New York'},
7 {'name': 'Alice', 'age': 30, 'city': 'San Francisco'},
8 {'name': 'Bob', 'age': 35, 'city': 'Chicago'}
9]
10df = pd.DataFrame(data)
11
12# Define grid options
13grid_options = {
14 'columnDefs': [
15 {'headerName': 'Name', 'field': 'name', 'sortable': True, 'filter': True},
16 {'headerName': 'Age', 'field': 'age', 'sortable': True, 'filter': 'agNumberColumnFilter'},
17 {'headerName': 'City', 'field': 'city', 'sortable': True, 'filter': True},
18 ],
19}
20
21# Create and display the grid
22g = Grid(grid_data=df,
23 grid_options=grid_options,
24 show_toggle_edit=True,
25 sync_on_edit=True,
26 theme='ag-theme-balham')
27g