{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import os\n", "import json\n", "import re\n", "import pandas as pd\n", "\n", "from IPython.display import Javascript\n", "\n", "from ezaggrid import AgGrid, get_license" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "path = os.path.join('data', 'olympicWinners.json')\n", "df = pd.read_json(path)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Int64Index: 8618 entries, 0 to 8617\n", "Data columns (total 10 columns):\n", "age 8613 non-null float64\n", "athlete 8618 non-null object\n", "bronze 8618 non-null int64\n", "country 8618 non-null object\n", "date 8618 non-null datetime64[ns]\n", "gold 8618 non-null int64\n", "silver 8618 non-null int64\n", "sport 8618 non-null object\n", "total 8618 non-null int64\n", "year 8618 non-null int64\n", "dtypes: datetime64[ns](1), float64(1), int64(5), object(3)\n", "memory usage: 740.6+ KB\n" ] } ], "source": [ "df.info()" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "columnDefs = [\n", " {'headerName': \"Country\", 'field': \"country\", 'width': 120, 'rowGroup': True},\n", " {'headerName': \"Gold\", 'field': \"gold\", 'width': 100, 'aggFunc': 'sum', 'enableValue': True},\n", " {'headerName': \"Silver\", 'field': \"silver\", 'width': 100, 'aggFunc': 'sum', 'enableValue': True},\n", " {'headerName': \"Bronze\", 'field': \"bronze\", 'width': 100, 'aggFunc': 'sum', 'enableValue': True},\n", " {'headerName': \"Total\", 'field': \"total\", 'width': 100, 'aggFunc': 'avg', 'enableValue': True},\n", " {'headerName': \"Year\", 'field': \"year\", 'width': 90},\n", " {'headerName': \"Sport\", 'field': \"sport\", 'width': 110},\n", " {'headerName': \"Age\", 'field': \"age\", 'width': 90},\n", "]\n", "\n", "grid_options = {\n", " 'columnDefs': columnDefs,\n", " 'groupIncludeFooter': True,\n", " 'enableSorting': True,\n", " 'showToolPanel': False,\n", " 'toolPanelSuppressPivots': True,\n", " 'toolPanelSuppressPivotMode': True,\n", " 'autoGroupColumnDef': {\n", " 'headerName': \"Athlete\",\n", " 'field': \"athlete\",\n", " 'width': 200,\n", " 'cellRenderer':'agGroupCellRenderer',\n", " 'cellRendererParams': {\n", " 'footerValueGetter': '\"Total (\" + x + \")\"',\n", " 'padding': 15\n", " }\n", " }\n", "}\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "ag = AgGrid(grid_data=df[:],\n", " grid_options=grid_options,\n", " css_rules=None,\n", " width=850,\n", " height=500,\n", " quick_filter=False,\n", " export_csv=False,\n", " export_excel=False,\n", " implicit_col_defs=False,\n", " theme='ag-theme-fresh',\n", " license=get_license())\n", "ag.show()" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" } }, "nbformat": 4, "nbformat_minor": 2 }