| 1 |
{ |
| 2 |
"cells": [ |
| 3 |
{ |
| 4 |
"cell_type": "code", |
| 5 |
"execution_count": null, |
| 6 |
"id": "e0cab8f8", |
| 7 |
"metadata": {}, |
| 8 |
"outputs": [], |
| 9 |
"source": [ |
| 10 |
"import pandas as pd\n", |
| 11 |
"import numpy as np\n", |
| 12 |
"import ipydatagrid as grid\n", |
| 13 |
"\n", |
| 14 |
"df = pd.DataFrame({'column 1': [1000,np.nan,0], 'column 2': [3,np.nan,9]})\n", |
| 15 |
"\n", |
| 16 |
"renderers = {\n", |
| 17 |
" 'column 2': grid.TextRenderer(text_value=grid.VegaExpr(\n", |
| 18 |
" \"\"\"\n", |
| 19 |
" if(\n", |
| 20 |
" !isValid(cell.value),\n", |
| 21 |
" 'THIS CELL NA',\n", |
| 22 |
" format(cell.value, ',.2s'))\n", |
| 23 |
" \"\"\")),\n", |
| 24 |
" 'column 1': grid.TextRenderer(text_value=grid.VegaExpr(\n", |
| 25 |
" \"\"\"\n", |
| 26 |
" if(\n", |
| 27 |
" !isValid(cell.value),\n", |
| 28 |
" 'THIS CELL NA',\n", |
| 29 |
" if(\n", |
| 30 |
" cell.value==0,\n", |
| 31 |
" ' ',\n", |
| 32 |
" format(cell.value, ',.2f')\n", |
| 33 |
" )\n", |
| 34 |
" )\n", |
| 35 |
" \"\"\"))\n", |
| 36 |
"}\n", |
| 37 |
"\n", |
| 38 |
"grid.DataGrid(df, base_column_size=110, renderers=renderers, layout={'height':'100px'})" |
| 39 |
] |
| 40 |
} |
| 41 |
], |
| 42 |
"metadata": { |
| 43 |
"kernelspec": { |
| 44 |
"display_name": "Python 3 (ipykernel)", |
| 45 |
"language": "python", |
| 46 |
"name": "python3" |
| 47 |
}, |
| 48 |
"language_info": { |
| 49 |
"codemirror_mode": { |
| 50 |
"name": "ipython", |
| 51 |
"version": 3 |
| 52 |
}, |
| 53 |
"file_extension": ".py", |
| 54 |
"mimetype": "text/x-python", |
| 55 |
"name": "python", |
| 56 |
"nbconvert_exporter": "python", |
| 57 |
"pygments_lexer": "ipython3", |
| 58 |
"version": "3.9.9" |
| 59 |
} |
| 60 |
}, |
| 61 |
"nbformat": 4, |
| 62 |
"nbformat_minor": 5 |
| 63 |
} |