%load_ext autoreload
%autoreload 2
import os
import json
import re
import pandas as pd
from IPython.display import Javascript
from ezaggrid import AgGrid, get_license
path = os.path.join('data', 'olympicWinners.json')
df = pd.read_json(path)
df.info()
<class 'pandas.core.frame.DataFrame'> Int64Index: 8618 entries, 0 to 8617 Data columns (total 10 columns): age 8613 non-null float64 athlete 8618 non-null object bronze 8618 non-null int64 country 8618 non-null object date 8618 non-null datetime64[ns] gold 8618 non-null int64 silver 8618 non-null int64 sport 8618 non-null object total 8618 non-null int64 year 8618 non-null int64 dtypes: datetime64[ns](1), float64(1), int64(5), object(3) memory usage: 740.6+ KB
columnDefs = [
{'headerName': "Country", 'field': "country", 'width': 120, 'rowGroup': True},
{'headerName': "Gold", 'field': "gold", 'width': 100, 'aggFunc': 'sum', 'enableValue': True},
{'headerName': "Silver", 'field': "silver", 'width': 100, 'aggFunc': 'sum', 'enableValue': True},
{'headerName': "Bronze", 'field': "bronze", 'width': 100, 'aggFunc': 'sum', 'enableValue': True},
{'headerName': "Total", 'field': "total", 'width': 100, 'aggFunc': 'avg', 'enableValue': True},
{'headerName': "Year", 'field': "year", 'width': 90},
{'headerName': "Sport", 'field': "sport", 'width': 110},
{'headerName': "Age", 'field': "age", 'width': 90},
]
grid_options = {
'columnDefs': columnDefs,
'groupIncludeFooter': True,
'enableSorting': True,
'showToolPanel': False,
'toolPanelSuppressPivots': True,
'toolPanelSuppressPivotMode': True,
'autoGroupColumnDef': {
'headerName': "Athlete",
'field': "athlete",
'width': 200,
'cellRenderer':'agGroupCellRenderer',
'cellRendererParams': {
'footerValueGetter': '"Total (" + x + ")"',
'padding': 15
}
}
}
ag = AgGrid(grid_data=df[:],
grid_options=grid_options,
css_rules=None,
width=850,
height=500,
quick_filter=False,
export_csv=False,
export_excel=False,
implicit_col_defs=False,
theme='ag-theme-fresh',
license=get_license())
ag.show()