Created
June 6, 2024 13:15
-
-
Save Jolanrensen/a50ca712d0bed01148e8af2a5a70ceee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"collapsed": true, | |
"ExecuteTime": { | |
"end_time": "2024-06-06T13:12:07.969748095Z", | |
"start_time": "2024-06-06T13:12:01.217468924Z" | |
} | |
}, | |
"source": "%use dataframe", | |
"outputs": [], | |
"execution_count": 1 | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2024-06-06T13:12:15.282384352Z", | |
"start_time": "2024-06-06T13:12:14.151517445Z" | |
} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"val df = dataFrameOf(\"firstName\", \"lastName\", \"age\", \"city\", \"weight\", \"isHappy\")(\n", | |
" \"Alice\", \"Cooper\", 15, \"London\", 54, true,\n", | |
" \"Bob\", \"Dylan\", 45, \"Dubai\", 87, true,\n", | |
" \"Charlie\", \"Daniels\", 20, \"Moscow\", null, false,\n", | |
" \"Charlie\", \"Chaplin\", 40, \"Milan\", null, true,\n", | |
" \"Bob\", \"Marley\", 30, \"Tokyo\", 68, true,\n", | |
" \"Alice\", \"Wolf\", 20, null, 55, false,\n", | |
" \"Charlie\", \"Byrd\", 30, \"Moscow\", 90, true\n", | |
").group(\"firstName\", \"lastName\").into(\"name\")\n", | |
"df" | |
], | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
" <iframe onload=\"o_resize_iframe_out_1()\" style=\"width:100%;\" class=\"result_container\" id=\"iframe_out_1\" frameBorder=\"0\" srcdoc=\" <html theme='dark'>\n", | |
" <head>\n", | |
" <style type="text/css">\n", | |
" :root {\n", | |
" --background: #fff;\n", | |
" --background-odd: #f5f5f5;\n", | |
" --background-hover: #d9edfd;\n", | |
" --header-text-color: #474747;\n", | |
" --text-color: #848484;\n", | |
" --text-color-dark: #000;\n", | |
" --text-color-medium: #737373;\n", | |
" --text-color-pale: #b3b3b3;\n", | |
" --inner-border-color: #aaa;\n", | |
" --bold-border-color: #000;\n", | |
" --link-color: #296eaa;\n", | |
" --link-color-pale: #296eaa;\n", | |
" --link-hover: #1a466c;\n", | |
"}\n", | |
"\n", | |
":root[theme="dark"], :root [data-jp-theme-light="false"], .dataframe_dark{\n", | |
" --background: #303030;\n", | |
" --background-odd: #3c3c3c;\n", | |
" --background-hover: #464646;\n", | |
" --header-text-color: #dddddd;\n", | |
" --text-color: #b3b3b3;\n", | |
" --text-color-dark: #dddddd;\n", | |
" --text-color-medium: #b2b2b2;\n", | |
" --text-color-pale: #737373;\n", | |
" --inner-border-color: #707070;\n", | |
" --bold-border-color: #777777;\n", | |
" --link-color: #008dc0;\n", | |
" --link-color-pale: #97e1fb;\n", | |
" --link-hover: #00688e;\n", | |
"}\n", | |
"\n", | |
"p.dataframe_description {\n", | |
" color: var(--text-color-dark);\n", | |
"}\n", | |
"\n", | |
"table.dataframe {\n", | |
" font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;\n", | |
" font-size: 12px;\n", | |
" background-color: var(--background);\n", | |
" color: var(--text-color-dark);\n", | |
" border: none;\n", | |
" border-collapse: collapse;\n", | |
"}\n", | |
"\n", | |
"table.dataframe th, td {\n", | |
" padding: 6px;\n", | |
" border: 1px solid transparent;\n", | |
" text-align: left;\n", | |
"}\n", | |
"\n", | |
"table.dataframe th {\n", | |
" background-color: var(--background);\n", | |
" color: var(--header-text-color);\n", | |
"}\n", | |
"\n", | |
"table.dataframe td {\n", | |
" vertical-align: top;\n", | |
"}\n", | |
"\n", | |
"table.dataframe th.bottomBorder {\n", | |
" border-bottom-color: var(--bold-border-color);\n", | |
"}\n", | |
"\n", | |
"table.dataframe tbody > tr:nth-child(odd) {\n", | |
" background: var(--background-odd);\n", | |
"}\n", | |
"\n", | |
"table.dataframe tbody > tr:nth-child(even) {\n", | |
" background: var(--background);\n", | |
"}\n", | |
"\n", | |
"table.dataframe tbody > tr:hover {\n", | |
" background: var(--background-hover);\n", | |
"}\n", | |
"\n", | |
"table.dataframe a {\n", | |
" cursor: pointer;\n", | |
" color: var(--link-color);\n", | |
" text-decoration: none;\n", | |
"}\n", | |
"\n", | |
"table.dataframe tr:hover > td a {\n", | |
" color: var(--link-color-pale);\n", | |
"}\n", | |
"\n", | |
"table.dataframe a:hover {\n", | |
" color: var(--link-hover);\n", | |
" text-decoration: underline;\n", | |
"}\n", | |
"\n", | |
"table.dataframe img {\n", | |
" max-width: fit-content;\n", | |
"}\n", | |
"\n", | |
"table.dataframe th.complex {\n", | |
" background-color: var(--background);\n", | |
" border: 1px solid var(--background);\n", | |
"}\n", | |
"\n", | |
"table.dataframe .leftBorder {\n", | |
" border-left-color: var(--inner-border-color);\n", | |
"}\n", | |
"\n", | |
"table.dataframe .rightBorder {\n", | |
" border-right-color: var(--inner-border-color);\n", | |
"}\n", | |
"\n", | |
"table.dataframe .rightAlign {\n", | |
" text-align: right;\n", | |
"}\n", | |
"\n", | |
"table.dataframe .expanderSvg {\n", | |
" width: 8px;\n", | |
" height: 8px;\n", | |
" margin-right: 3px;\n", | |
"}\n", | |
"\n", | |
"table.dataframe .expander {\n", | |
" display: flex;\n", | |
" align-items: center;\n", | |
"}\n", | |
"\n", | |
"/* formatting */\n", | |
"\n", | |
"table.dataframe .null {\n", | |
" color: var(--text-color-pale);\n", | |
"}\n", | |
"\n", | |
"table.dataframe .structural {\n", | |
" color: var(--text-color-medium);\n", | |
" font-weight: bold;\n", | |
"}\n", | |
"\n", | |
"table.dataframe .dataFrameCaption {\n", | |
" font-weight: bold;\n", | |
"}\n", | |
"\n", | |
"table.dataframe .numbers {\n", | |
" color: var(--text-color-dark);\n", | |
"}\n", | |
"\n", | |
"table.dataframe td:hover .formatted .structural, .null {\n", | |
" color: var(--text-color-dark);\n", | |
"}\n", | |
"\n", | |
"table.dataframe tr:hover .formatted .structural, .null {\n", | |
" color: var(--text-color-dark);\n", | |
"}\n", | |
"\n", | |
"\n", | |
":root {\n", | |
" --scroll-bg: #f5f5f5;\n", | |
" --scroll-fg: #b3b3b3;\n", | |
"}\n", | |
":root[theme="dark"], :root [data-jp-theme-light="false"]{\n", | |
" --scroll-bg: #3c3c3c;\n", | |
" --scroll-fg: #97e1fb;\n", | |
"}\n", | |
"body {\n", | |
" scrollbar-color: var(--scroll-fg) var(--scroll-bg);\n", | |
"}\n", | |
"body::-webkit-scrollbar {\n", | |
" width: 10px; /* Mostly for vertical scrollbars */\n", | |
" height: 10px; /* Mostly for horizontal scrollbars */\n", | |
"}\n", | |
"body::-webkit-scrollbar-thumb {\n", | |
" background-color: var(--scroll-fg);\n", | |
"}\n", | |
"body::-webkit-scrollbar-track {\n", | |
" background-color: var(--scroll-bg);\n", | |
"}\n", | |
" </style>\n", | |
" </head>\n", | |
" <body>\n", | |
" <table class="dataframe" id="df_1879048192"></table>\n", | |
"\n", | |
"<p class="dataframe_description">DataFrame: rowsCount = 7, columnsCount = 5</p>\n", | |
"\n", | |
" </body>\n", | |
" <script>\n", | |
" (function () {\n", | |
" window.DataFrame = window.DataFrame || new (function () {\n", | |
" this.addTable = function (df) {\n", | |
" let cols = df.cols;\n", | |
" for (let i = 0; i < cols.length; i++) {\n", | |
" for (let c of cols[i].children) {\n", | |
" cols[c].parent = i;\n", | |
" }\n", | |
" }\n", | |
" df.nrow = 0\n", | |
" for (let i = 0; i < df.cols.length; i++) {\n", | |
" if (df.cols[i].values.length > df.nrow) df.nrow = df.cols[i].values.length\n", | |
" }\n", | |
" if (df.id === df.rootId) {\n", | |
" df.expandedFrames = new Set()\n", | |
" df.childFrames = {}\n", | |
" const table = this.getTableElement(df.id)\n", | |
" table.df = df\n", | |
" for (let i = 0; i < df.cols.length; i++) {\n", | |
" let col = df.cols[i]\n", | |
" if (col.parent === undefined && col.children.length > 0) col.expanded = true\n", | |
" }\n", | |
" } else {\n", | |
" const rootDf = this.getTableData(df.rootId)\n", | |
" rootDf.childFrames[df.id] = df\n", | |
" }\n", | |
" }\n", | |
"\n", | |
" this.computeRenderData = function (df) {\n", | |
" let result = []\n", | |
" let pos = 0\n", | |
" for (let col = 0; col < df.cols.length; col++) {\n", | |
" if (df.cols[col].parent === undefined)\n", | |
" pos += this.computeRenderDataRec(df.cols, col, pos, 0, result, false, false)\n", | |
" }\n", | |
" for (let i = 0; i < result.length; i++) {\n", | |
" let row = result[i]\n", | |
" for (let j = 0; j < row.length; j++) {\n", | |
" let cell = row[j]\n", | |
" if (j === 0)\n", | |
" cell.leftBd = false\n", | |
" if (j < row.length - 1) {\n", | |
" let nextData = row[j + 1]\n", | |
" if (nextData.leftBd) cell.rightBd = true\n", | |
" else if (cell.rightBd) nextData.leftBd = true\n", | |
" } else cell.rightBd = false\n", | |
" }\n", | |
" }\n", | |
" return result\n", | |
" }\n", | |
"\n", | |
" this.computeRenderDataRec = function (cols, colId, pos, depth, result, leftBorder, rightBorder) {\n", | |
" if (result.length === depth) {\n", | |
" const array = [];\n", | |
" if (pos > 0) {\n", | |
" let j = 0\n", | |
" for (let i = 0; j < pos; i++) {\n", | |
" let c = result[depth - 1][i]\n", | |
" j += c.span\n", | |
" let copy = Object.assign({empty: true}, c)\n", | |
" array.push(copy)\n", | |
" }\n", | |
" }\n", | |
" result.push(array)\n", | |
" }\n", | |
" const col = cols[colId];\n", | |
" let size = 0;\n", | |
" if (col.expanded) {\n", | |
" let childPos = pos\n", | |
" for (let i = 0; i < col.children.length; i++) {\n", | |
" let child = col.children[i]\n", | |
" let childLeft = i === 0 && (col.children.length > 1 || leftBorder)\n", | |
" let childRight = i === col.children.length - 1 && (col.children.length > 1 || rightBorder)\n", | |
" let childSize = this.computeRenderDataRec(cols, child, childPos, depth + 1, result, childLeft, childRight)\n", | |
" childPos += childSize\n", | |
" size += childSize\n", | |
" }\n", | |
" } else {\n", | |
" for (let i = depth + 1; i < result.length; i++)\n", | |
" result[i].push({id: colId, span: 1, leftBd: leftBorder, rightBd: rightBorder, empty: true})\n", | |
" size = 1\n", | |
" }\n", | |
" let left = leftBorder\n", | |
" let right = rightBorder\n", | |
" if (size > 1) {\n", | |
" left = true\n", | |
" right = true\n", | |
" }\n", | |
" result[depth].push({id: colId, span: size, leftBd: left, rightBd: right})\n", | |
" return size\n", | |
" }\n", | |
"\n", | |
" this.getTableElement = function (id) {\n", | |
" return document.getElementById("df_" + id)\n", | |
" }\n", | |
"\n", | |
" this.getTableData = function (id) {\n", | |
" return this.getTableElement(id).df\n", | |
" }\n", | |
"\n", | |
" this.createExpander = function (isExpanded) {\n", | |
" const svgNs = "http://www.w3.org/2000/svg"\n", | |
" let svg = document.createElementNS(svgNs, "svg")\n", | |
" svg.classList.add("expanderSvg")\n", | |
" let path = document.createElementNS(svgNs, "path")\n", | |
" if (isExpanded) {\n", | |
" svg.setAttribute("viewBox", "0 -2 8 8")\n", | |
" path.setAttribute("d", "M1 0 l-1 1 4 4 4 -4 -1 -1 -3 3Z")\n", | |
" } else {\n", | |
" svg.setAttribute("viewBox", "-2 0 8 8")\n", | |
" path.setAttribute("d", "M1 0 l-1 1 3 3 -3 3 1 1 4 -4Z")\n", | |
" }\n", | |
" path.setAttribute("fill", "currentColor")\n", | |
" svg.appendChild(path)\n", | |
" return svg\n", | |
" }\n", | |
"\n", | |
" this.renderTable = function (id) {\n", | |
"\n", | |
" let table = this.getTableElement(id)\n", | |
"\n", | |
" if (table === null) return\n", | |
"\n", | |
" table.innerHTML = ""\n", | |
"\n", | |
" let df = table.df\n", | |
" let rootDf = df.rootId === df.id ? df : this.getTableData(df.rootId)\n", | |
"\n", | |
" // header\n", | |
" let header = document.createElement("thead")\n", | |
" table.appendChild(header)\n", | |
"\n", | |
" let renderData = this.computeRenderData(df)\n", | |
" for (let j = 0; j < renderData.length; j++) {\n", | |
" let rowData = renderData[j]\n", | |
" let tr = document.createElement("tr");\n", | |
" let isLastRow = j === renderData.length - 1\n", | |
" header.appendChild(tr);\n", | |
" for (let i = 0; i < rowData.length; i++) {\n", | |
" let cell = rowData[i]\n", | |
" let th = document.createElement("th");\n", | |
" th.setAttribute("colspan", cell.span)\n", | |
" let colId = cell.id\n", | |
" let col = df.cols[colId];\n", | |
" if (!cell.empty) {\n", | |
" if (col.children.length === 0) {\n", | |
" th.innerHTML = col.name\n", | |
" } else {\n", | |
" let link = document.createElement("a")\n", | |
" link.className = "expander"\n", | |
" let that = this\n", | |
" link.onclick = function () {\n", | |
" col.expanded = !col.expanded\n", | |
" that.renderTable(id)\n", | |
" }\n", | |
" link.appendChild(this.createExpander(col.expanded))\n", | |
" link.innerHTML += col.name\n", | |
" th.appendChild(link)\n", | |
" }\n", | |
" }\n", | |
" let classes = (cell.leftBd ? " leftBorder" : "") + (cell.rightBd ? " rightBorder" : "")\n", | |
" if (col.rightAlign)\n", | |
" classes += " rightAlign"\n", | |
" if (isLastRow)\n", | |
" classes += " bottomBorder"\n", | |
" if (classes.length > 0)\n", | |
" th.setAttribute("class", classes)\n", | |
" tr.appendChild(th)\n", | |
" }\n", | |
" }\n", | |
"\n", | |
" // body\n", | |
" let body = document.createElement("tbody")\n", | |
" table.appendChild(body)\n", | |
"\n", | |
" let columns = renderData.pop()\n", | |
" for (let row = 0; row < df.nrow; row++) {\n", | |
" let tr = document.createElement("tr");\n", | |
" body.appendChild(tr)\n", | |
" for (let i = 0; i < columns.length; i++) {\n", | |
" let cell = columns[i]\n", | |
" let td = document.createElement("td");\n", | |
" let colId = cell.id\n", | |
" let col = df.cols[colId]\n", | |
" let classes = (cell.leftBd ? " leftBorder" : "") + (cell.rightBd ? " rightBorder" : "")\n", | |
" if (col.rightAlign)\n", | |
" classes += " rightAlign"\n", | |
" if (classes.length > 0)\n", | |
" td.setAttribute("class", classes)\n", | |
" tr.appendChild(td)\n", | |
" let value = col.values[row]\n", | |
" if (value.frameId !== undefined) {\n", | |
" let frameId = value.frameId\n", | |
" let expanded = rootDf.expandedFrames.has(frameId)\n", | |
" let link = document.createElement("a")\n", | |
" link.className = "expander"\n", | |
" let that = this\n", | |
" link.onclick = function () {\n", | |
" if (rootDf.expandedFrames.has(frameId))\n", | |
" rootDf.expandedFrames.delete(frameId)\n", | |
" else rootDf.expandedFrames.add(frameId)\n", | |
" that.renderTable(id)\n", | |
" }\n", | |
" link.appendChild(this.createExpander(expanded))\n", | |
" link.innerHTML += value.value\n", | |
" if (expanded) {\n", | |
" td.appendChild(link)\n", | |
" td.appendChild(document.createElement("p"))\n", | |
" const childTable = document.createElement("table")\n", | |
" childTable.className = "dataframe"\n", | |
" childTable.id = "df_" + frameId\n", | |
" let childDf = rootDf.childFrames[frameId]\n", | |
" childTable.df = childDf\n", | |
" td.appendChild(childTable)\n", | |
" this.renderTable(frameId)\n", | |
" if (childDf.nrow !== childDf.totalRows) {\n", | |
" const footer = document.createElement("p")\n", | |
" footer.innerText = `... showing only top ${childDf.nrow} of ${childDf.totalRows} rows`\n", | |
" td.appendChild(footer)\n", | |
" }\n", | |
" } else {\n", | |
" td.appendChild(link)\n", | |
" }\n", | |
" } else if (value.style !== undefined) {\n", | |
" td.innerHTML = value.value\n", | |
" td.setAttribute("style", value.style)\n", | |
" } else td.innerHTML = value\n", | |
" this.nodeScriptReplace(td)\n", | |
" }\n", | |
" }\n", | |
" }\n", | |
"\n", | |
" this.nodeScriptReplace = function (node) {\n", | |
" if (this.nodeScriptIs(node) === true) {\n", | |
" node.parentNode.replaceChild(this.nodeScriptClone(node), node);\n", | |
" } else {\n", | |
" let i = -1, children = node.childNodes;\n", | |
" while (++i < children.length) {\n", | |
" this.nodeScriptReplace(children[i]);\n", | |
" }\n", | |
" }\n", | |
"\n", | |
" return node;\n", | |
" }\n", | |
"\n", | |
" this.nodeScriptClone = function (node) {\n", | |
" let script = document.createElement("script");\n", | |
" script.text = node.innerHTML;\n", | |
"\n", | |
" let i = -1, attrs = node.attributes, attr;\n", | |
" while (++i < attrs.length) {\n", | |
" script.setAttribute((attr = attrs[i]).name, attr.value);\n", | |
" }\n", | |
" return script;\n", | |
" }\n", | |
"\n", | |
" this.nodeScriptIs = function (node) {\n", | |
" return node.tagName === 'SCRIPT';\n", | |
" }\n", | |
" })()\n", | |
"\n", | |
" window.call_DataFrame = function (f) {\n", | |
" return f();\n", | |
" };\n", | |
"\n", | |
" let funQueue = window["kotlinQueues"] && window["kotlinQueues"]["DataFrame"];\n", | |
" if (funQueue) {\n", | |
" funQueue.forEach(function (f) {\n", | |
" f();\n", | |
" });\n", | |
" funQueue = [];\n", | |
" }\n", | |
"})()\n", | |
"\n", | |
"/*<!--*/\n", | |
"call_DataFrame(function() { DataFrame.addTable({ cols: [{ name: "<span title=\"firstName: String\">firstName</span>", children: [], rightAlign: false, values: ["Alice","Bob","Charlie","Charlie","Bob","Alice","Charlie"] }, \n", | |
"{ name: "<span title=\"lastName: String\">lastName</span>", children: [], rightAlign: false, values: ["Cooper","Dylan","Daniels","Chaplin","Marley","Wolf","Byrd"] }, \n", | |
"{ name: "<span title=\"name: DataRow<*>\">name</span>", children: [0, 1], rightAlign: false, values: ["<span class=\"formatted\" title=\"firstName: Alice\nlastName: Cooper\"><span class=\"structural\">{ </span><span class=\"structural\">firstName: </span>Alice<span class=\"structural\">, </span><span class=\"structural\">lastName: </span>Cooper<span class=\"structural\"> }</span></span>","<span class=\"formatted\" title=\"firstName: Bob\nlastName: Dylan\"><span class=\"structural\">{ </span><span class=\"structural\">firstName: </span>Bob<span class=\"structural\">, </span><span class=\"structural\">lastName: </span>Dylan<span class=\"structural\"> }</span></span>","<span class=\"formatted\" title=\"firstName: Charlie\nlastName: Daniels\"><span class=\"structural\">{ </span><span class=\"structural\">firstName: </span>Charlie<span class=\"structural\">, </span><span class=\"structural\">lastName: </span>Dan<span class=\"structural\">...</span><span class=\"structural\"> }</span></span>","<span class=\"formatted\" title=\"firstName: Charlie\nlastName: Chaplin\"><span class=\"structural\">{ </span><span class=\"structural\">firstName: </span>Charlie<span class=\"structural\">, </span><span class=\"structural\">lastName: </span>Cha<span class=\"structural\">...</span><span class=\"structural\"> }</span></span>","<span class=\"formatted\" title=\"firstName: Bob\nlastName: Marley\"><span class=\"structural\">{ </span><span class=\"structural\">firstName: </span>Bob<span class=\"structural\">, </span><span class=\"structural\">lastName: </span>Marley<span class=\"structural\"> }</span></span>","<span class=\"formatted\" title=\"firstName: Alice\nlastName: Wolf\"><span class=\"structural\">{ </span><span class=\"structural\">firstName: </span>Alice<span class=\"structural\">, </span><span class=\"structural\">lastName: </span>Wolf<span class=\"structural\"> }</span></span>","<span class=\"formatted\" title=\"firstName: Charlie\nlastName: Byrd\"><span class=\"structural\">{ </span><span class=\"structural\">firstName: </span>Charlie<span class=\"structural\">, </span><span class=\"structural\">lastName: </span>Byrd<span class=\"structural\"> }</span></span>"] }, \n", | |
"{ name: "<span title=\"age: Int\">age</span>", children: [], rightAlign: true, values: ["<span class=\"formatted\" title=\"\"><span class=\"numbers\">15</span></span>","<span class=\"formatted\" title=\"\"><span class=\"numbers\">45</span></span>","<span class=\"formatted\" title=\"\"><span class=\"numbers\">20</span></span>","<span class=\"formatted\" title=\"\"><span class=\"numbers\">40</span></span>","<span class=\"formatted\" title=\"\"><span class=\"numbers\">30</span></span>","<span class=\"formatted\" title=\"\"><span class=\"numbers\">20</span></span>","<span class=\"formatted\" title=\"\"><span class=\"numbers\">30</span></span>"] }, \n", | |
"{ name: "<span title=\"city: String?\">city</span>", children: [], rightAlign: false, values: ["London","Dubai","Moscow","Milan","Tokyo","<span class=\"formatted\" title=\"\"><span class=\"null\">null</span></span>","Moscow"] }, \n", | |
"{ name: "<span title=\"weight: Int?\">weight</span>", children: [], rightAlign: true, values: ["<span class=\"formatted\" title=\"\"><span class=\"numbers\">54</span></span>","<span class=\"formatted\" title=\"\"><span class=\"numbers\">87</span></span>","<span class=\"formatted\" title=\"\"><span class=\"null\">null</span></span>","<span class=\"formatted\" title=\"\"><span class=\"null\">null</span></span>","<span class=\"formatted\" title=\"\"><span class=\"numbers\">68</span></span>","<span class=\"formatted\" title=\"\"><span class=\"numbers\">55</span></span>","<span class=\"formatted\" title=\"\"><span class=\"numbers\">90</span></span>"] }, \n", | |
"{ name: "<span title=\"isHappy: Boolean\">isHappy</span>", children: [], rightAlign: false, values: ["true","true","false","true","true","false","true"] }, \n", | |
"], id: 1879048192, rootId: 1879048192, totalRows: 7 } ) });\n", | |
"/*-->*/\n", | |
"\n", | |
"call_DataFrame(function() { DataFrame.renderTable(1879048192) });\n", | |
"\n", | |
"\n", | |
" </script>\n", | |
" </html>\"></iframe>\n", | |
" <script>\n", | |
" function o_resize_iframe_out_1() {\n", | |
" let elem = document.getElementById(\"iframe_out_1\");\n", | |
" resize_iframe_out_1(elem);\n", | |
" setInterval(resize_iframe_out_1, 5000, elem);\n", | |
" }\n", | |
" function resize_iframe_out_1(el) {\n", | |
" let h = el.contentWindow.document.body.scrollHeight;\n", | |
" el.height = h === 0 ? 0 : h + 41;\n", | |
" }\n", | |
" </script> <html theme='dark'>\n", | |
" <head>\n", | |
" <style type=\"text/css\">\n", | |
" :root {\n", | |
" --background: #fff;\n", | |
" --background-odd: #f5f5f5;\n", | |
" --background-hover: #d9edfd;\n", | |
" --header-text-color: #474747;\n", | |
" --text-color: #848484;\n", | |
" --text-color-dark: #000;\n", | |
" --text-color-medium: #737373;\n", | |
" --text-color-pale: #b3b3b3;\n", | |
" --inner-border-color: #aaa;\n", | |
" --bold-border-color: #000;\n", | |
" --link-color: #296eaa;\n", | |
" --link-color-pale: #296eaa;\n", | |
" --link-hover: #1a466c;\n", | |
"}\n", | |
"\n", | |
":root[theme=\"dark\"], :root [data-jp-theme-light=\"false\"], .dataframe_dark{\n", | |
" --background: #303030;\n", | |
" --background-odd: #3c3c3c;\n", | |
" --background-hover: #464646;\n", | |
" --header-text-color: #dddddd;\n", | |
" --text-color: #b3b3b3;\n", | |
" --text-color-dark: #dddddd;\n", | |
" --text-color-medium: #b2b2b2;\n", | |
" --text-color-pale: #737373;\n", | |
" --inner-border-color: #707070;\n", | |
" --bold-border-color: #777777;\n", | |
" --link-color: #008dc0;\n", | |
" --link-color-pale: #97e1fb;\n", | |
" --link-hover: #00688e;\n", | |
"}\n", | |
"\n", | |
"p.dataframe_description {\n", | |
" color: var(--text-color-dark);\n", | |
"}\n", | |
"\n", | |
"table.dataframe {\n", | |
" font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n", | |
" font-size: 12px;\n", | |
" background-color: var(--background);\n", | |
" color: var(--text-color-dark);\n", | |
" border: none;\n", | |
" border-collapse: collapse;\n", | |
"}\n", | |
"\n", | |
"table.dataframe th, td {\n", | |
" padding: 6px;\n", | |
" border: 1px solid transparent;\n", | |
" text-align: left;\n", | |
"}\n", | |
"\n", | |
"table.dataframe th {\n", | |
" background-color: var(--background);\n", | |
" color: var(--header-text-color);\n", | |
"}\n", | |
"\n", | |
"table.dataframe td {\n", | |
" vertical-align: top;\n", | |
"}\n", | |
"\n", | |
"table.dataframe th.bottomBorder {\n", | |
" border-bottom-color: var(--bold-border-color);\n", | |
"}\n", | |
"\n", | |
"table.dataframe tbody > tr:nth-child(odd) {\n", | |
" background: var(--background-odd);\n", | |
"}\n", | |
"\n", | |
"table.dataframe tbody > tr:nth-child(even) {\n", | |
" background: var(--background);\n", | |
"}\n", | |
"\n", | |
"table.dataframe tbody > tr:hover {\n", | |
" background: var(--background-hover);\n", | |
"}\n", | |
"\n", | |
"table.dataframe a {\n", | |
" cursor: pointer;\n", | |
" color: var(--link-color);\n", | |
" text-decoration: none;\n", | |
"}\n", | |
"\n", | |
"table.dataframe tr:hover > td a {\n", | |
" color: var(--link-color-pale);\n", | |
"}\n", | |
"\n", | |
"table.dataframe a:hover {\n", | |
" color: var(--link-hover);\n", | |
" text-decoration: underline;\n", | |
"}\n", | |
"\n", | |
"table.dataframe img {\n", | |
" max-width: fit-content;\n", | |
"}\n", | |
"\n", | |
"table.dataframe th.complex {\n", | |
" background-color: var(--background);\n", | |
" border: 1px solid var(--background);\n", | |
"}\n", | |
"\n", | |
"table.dataframe .leftBorder {\n", | |
" border-left-color: var(--inner-border-color);\n", | |
"}\n", | |
"\n", | |
"table.dataframe .rightBorder {\n", | |
" border-right-color: var(--inner-border-color);\n", | |
"}\n", | |
"\n", | |
"table.dataframe .rightAlign {\n", | |
" text-align: right;\n", | |
"}\n", | |
"\n", | |
"table.dataframe .expanderSvg {\n", | |
" width: 8px;\n", | |
" height: 8px;\n", | |
" margin-right: 3px;\n", | |
"}\n", | |
"\n", | |
"table.dataframe .expander {\n", | |
" display: flex;\n", | |
" align-items: center;\n", | |
"}\n", | |
"\n", | |
"/* formatting */\n", | |
"\n", | |
"table.dataframe .null {\n", | |
" color: var(--text-color-pale);\n", | |
"}\n", | |
"\n", | |
"table.dataframe .structural {\n", | |
" color: var(--text-color-medium);\n", | |
" font-weight: bold;\n", | |
"}\n", | |
"\n", | |
"table.dataframe .dataFrameCaption {\n", | |
" font-weight: bold;\n", | |
"}\n", | |
"\n", | |
"table.dataframe .numbers {\n", | |
" color: var(--text-color-dark);\n", | |
"}\n", | |
"\n", | |
"table.dataframe td:hover .formatted .structural, .null {\n", | |
" color: var(--text-color-dark);\n", | |
"}\n", | |
"\n", | |
"table.dataframe tr:hover .formatted .structural, .null {\n", | |
" color: var(--text-color-dark);\n", | |
"}\n", | |
"\n", | |
"\n", | |
" </style>\n", | |
" </head>\n", | |
" <body>\n", | |
" <table class=\"dataframe\" id=\"static_df_1879048193\"><thead><tr><th style=\"text-align:left\">name</th><th class=\"rightBorder\" style=\"text-align:left\"></th><th style=\"text-align:left\">age</th><th style=\"text-align:left\">city</th><th style=\"text-align:left\">weight</th><th style=\"text-align:left\">isHappy</th></tr><tr><th class=\"bottomBorder\" style=\"text-align:left\">firstName</th><th class=\"bottomBorder rightBorder\" style=\"text-align:left\">lastName</th><th class=\"bottomBorder\" style=\"text-align:left\"></th><th class=\"bottomBorder\" style=\"text-align:left\"></th><th class=\"bottomBorder\" style=\"text-align:left\"></th><th class=\"bottomBorder\" style=\"text-align:left\"></th></tr></thead><tbody><tr><td style=\"vertical-align:top\">Alice</td><td class=\"rightBorder\" style=\"vertical-align:top\">Cooper</td><td style=\"vertical-align:top\">15</td><td style=\"vertical-align:top\">London</td><td style=\"vertical-align:top\">54</td><td style=\"vertical-align:top\">true</td></tr><tr><td style=\"vertical-align:top\">Bob</td><td class=\"rightBorder\" style=\"vertical-align:top\">Dylan</td><td style=\"vertical-align:top\">45</td><td style=\"vertical-align:top\">Dubai</td><td style=\"vertical-align:top\">87</td><td style=\"vertical-align:top\">true</td></tr><tr><td style=\"vertical-align:top\">Charlie</td><td class=\"rightBorder\" style=\"vertical-align:top\">Daniels</td><td style=\"vertical-align:top\">20</td><td style=\"vertical-align:top\">Moscow</td><td style=\"vertical-align:top\">null</td><td style=\"vertical-align:top\">false</td></tr><tr><td style=\"vertical-align:top\">Charlie</td><td class=\"rightBorder\" style=\"vertical-align:top\">Chaplin</td><td style=\"vertical-align:top\">40</td><td style=\"vertical-align:top\">Milan</td><td style=\"vertical-align:top\">null</td><td style=\"vertical-align:top\">true</td></tr><tr><td style=\"vertical-align:top\">Bob</td><td class=\"rightBorder\" style=\"vertical-align:top\">Marley</td><td style=\"vertical-align:top\">30</td><td style=\"vertical-align:top\">Tokyo</td><td style=\"vertical-align:top\">68</td><td style=\"vertical-align:top\">true</td></tr><tr><td style=\"vertical-align:top\">Alice</td><td class=\"rightBorder\" style=\"vertical-align:top\">Wolf</td><td style=\"vertical-align:top\">20</td><td style=\"vertical-align:top\">null</td><td style=\"vertical-align:top\">55</td><td style=\"vertical-align:top\">false</td></tr><tr><td style=\"vertical-align:top\">Charlie</td><td class=\"rightBorder\" style=\"vertical-align:top\">Byrd</td><td style=\"vertical-align:top\">30</td><td style=\"vertical-align:top\">Moscow</td><td style=\"vertical-align:top\">90</td><td style=\"vertical-align:top\">true</td></tr></tbody></table>\n", | |
" </body>\n", | |
" <script>\n", | |
" document.getElementById(\"static_df_1879048193\").style.display = \"none\";\n", | |
" </script>\n", | |
" </html>" | |
], | |
"application/kotlindataframe+json": "{\"$version\":\"2.0.0\",\"metadata\":{\"columns\":[\"name\",\"age\",\"city\",\"weight\",\"isHappy\"],\"nrow\":7,\"ncol\":5},\"kotlin_dataframe\":[{\"name\":{\"data\":{\"firstName\":\"Alice\",\"lastName\":\"Cooper\"},\"metadata\":{\"kind\":\"ColumnGroup\"}},\"age\":15,\"city\":\"London\",\"weight\":54,\"isHappy\":true},{\"name\":{\"data\":{\"firstName\":\"Bob\",\"lastName\":\"Dylan\"},\"metadata\":{\"kind\":\"ColumnGroup\"}},\"age\":45,\"city\":\"Dubai\",\"weight\":87,\"isHappy\":true},{\"name\":{\"data\":{\"firstName\":\"Charlie\",\"lastName\":\"Daniels\"},\"metadata\":{\"kind\":\"ColumnGroup\"}},\"age\":20,\"city\":\"Moscow\",\"weight\":null,\"isHappy\":false},{\"name\":{\"data\":{\"firstName\":\"Charlie\",\"lastName\":\"Chaplin\"},\"metadata\":{\"kind\":\"ColumnGroup\"}},\"age\":40,\"city\":\"Milan\",\"weight\":null,\"isHappy\":true},{\"name\":{\"data\":{\"firstName\":\"Bob\",\"lastName\":\"Marley\"},\"metadata\":{\"kind\":\"ColumnGroup\"}},\"age\":30,\"city\":\"Tokyo\",\"weight\":68,\"isHappy\":true},{\"name\":{\"data\":{\"firstName\":\"Alice\",\"lastName\":\"Wolf\"},\"metadata\":{\"kind\":\"ColumnGroup\"}},\"age\":20,\"city\":null,\"weight\":55,\"isHappy\":false},{\"name\":{\"data\":{\"firstName\":\"Charlie\",\"lastName\":\"Byrd\"},\"metadata\":{\"kind\":\"ColumnGroup\"}},\"age\":30,\"city\":\"Moscow\",\"weight\":90,\"isHappy\":true}]}" | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"execution_count": 3 | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2024-06-06T13:14:18.156168097Z", | |
"start_time": "2024-06-06T13:14:17.914760889Z" | |
} | |
}, | |
"cell_type": "code", | |
"source": [ | |
"val std = df.std()\n", | |
"std" | |
], | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
" <iframe onload=\"o_resize_iframe_out_8()\" style=\"width:100%;\" class=\"result_container\" id=\"iframe_out_8\" frameBorder=\"0\" srcdoc=\" <html theme='dark'>\n", | |
" <head>\n", | |
" <style type="text/css">\n", | |
" :root {\n", | |
" --background: #fff;\n", | |
" --background-odd: #f5f5f5;\n", | |
" --background-hover: #d9edfd;\n", | |
" --header-text-color: #474747;\n", | |
" --text-color: #848484;\n", | |
" --text-color-dark: #000;\n", | |
" --text-color-medium: #737373;\n", | |
" --text-color-pale: #b3b3b3;\n", | |
" --inner-border-color: #aaa;\n", | |
" --bold-border-color: #000;\n", | |
" --link-color: #296eaa;\n", | |
" --link-color-pale: #296eaa;\n", | |
" --link-hover: #1a466c;\n", | |
"}\n", | |
"\n", | |
":root[theme="dark"], :root [data-jp-theme-light="false"], .dataframe_dark{\n", | |
" --background: #303030;\n", | |
" --background-odd: #3c3c3c;\n", | |
" --background-hover: #464646;\n", | |
" --header-text-color: #dddddd;\n", | |
" --text-color: #b3b3b3;\n", | |
" --text-color-dark: #dddddd;\n", | |
" --text-color-medium: #b2b2b2;\n", | |
" --text-color-pale: #737373;\n", | |
" --inner-border-color: #707070;\n", | |
" --bold-border-color: #777777;\n", | |
" --link-color: #008dc0;\n", | |
" --link-color-pale: #97e1fb;\n", | |
" --link-hover: #00688e;\n", | |
"}\n", | |
"\n", | |
"p.dataframe_description {\n", | |
" color: var(--text-color-dark);\n", | |
"}\n", | |
"\n", | |
"table.dataframe {\n", | |
" font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;\n", | |
" font-size: 12px;\n", | |
" background-color: var(--background);\n", | |
" color: var(--text-color-dark);\n", | |
" border: none;\n", | |
" border-collapse: collapse;\n", | |
"}\n", | |
"\n", | |
"table.dataframe th, td {\n", | |
" padding: 6px;\n", | |
" border: 1px solid transparent;\n", | |
" text-align: left;\n", | |
"}\n", | |
"\n", | |
"table.dataframe th {\n", | |
" background-color: var(--background);\n", | |
" color: var(--header-text-color);\n", | |
"}\n", | |
"\n", | |
"table.dataframe td {\n", | |
" vertical-align: top;\n", | |
"}\n", | |
"\n", | |
"table.dataframe th.bottomBorder {\n", | |
" border-bottom-color: var(--bold-border-color);\n", | |
"}\n", | |
"\n", | |
"table.dataframe tbody > tr:nth-child(odd) {\n", | |
" background: var(--background-odd);\n", | |
"}\n", | |
"\n", | |
"table.dataframe tbody > tr:nth-child(even) {\n", | |
" background: var(--background);\n", | |
"}\n", | |
"\n", | |
"table.dataframe tbody > tr:hover {\n", | |
" background: var(--background-hover);\n", | |
"}\n", | |
"\n", | |
"table.dataframe a {\n", | |
" cursor: pointer;\n", | |
" color: var(--link-color);\n", | |
" text-decoration: none;\n", | |
"}\n", | |
"\n", | |
"table.dataframe tr:hover > td a {\n", | |
" color: var(--link-color-pale);\n", | |
"}\n", | |
"\n", | |
"table.dataframe a:hover {\n", | |
" color: var(--link-hover);\n", | |
" text-decoration: underline;\n", | |
"}\n", | |
"\n", | |
"table.dataframe img {\n", | |
" max-width: fit-content;\n", | |
"}\n", | |
"\n", | |
"table.dataframe th.complex {\n", | |
" background-color: var(--background);\n", | |
" border: 1px solid var(--background);\n", | |
"}\n", | |
"\n", | |
"table.dataframe .leftBorder {\n", | |
" border-left-color: var(--inner-border-color);\n", | |
"}\n", | |
"\n", | |
"table.dataframe .rightBorder {\n", | |
" border-right-color: var(--inner-border-color);\n", | |
"}\n", | |
"\n", | |
"table.dataframe .rightAlign {\n", | |
" text-align: right;\n", | |
"}\n", | |
"\n", | |
"table.dataframe .expanderSvg {\n", | |
" width: 8px;\n", | |
" height: 8px;\n", | |
" margin-right: 3px;\n", | |
"}\n", | |
"\n", | |
"table.dataframe .expander {\n", | |
" display: flex;\n", | |
" align-items: center;\n", | |
"}\n", | |
"\n", | |
"/* formatting */\n", | |
"\n", | |
"table.dataframe .null {\n", | |
" color: var(--text-color-pale);\n", | |
"}\n", | |
"\n", | |
"table.dataframe .structural {\n", | |
" color: var(--text-color-medium);\n", | |
" font-weight: bold;\n", | |
"}\n", | |
"\n", | |
"table.dataframe .dataFrameCaption {\n", | |
" font-weight: bold;\n", | |
"}\n", | |
"\n", | |
"table.dataframe .numbers {\n", | |
" color: var(--text-color-dark);\n", | |
"}\n", | |
"\n", | |
"table.dataframe td:hover .formatted .structural, .null {\n", | |
" color: var(--text-color-dark);\n", | |
"}\n", | |
"\n", | |
"table.dataframe tr:hover .formatted .structural, .null {\n", | |
" color: var(--text-color-dark);\n", | |
"}\n", | |
"\n", | |
"\n", | |
":root {\n", | |
" --scroll-bg: #f5f5f5;\n", | |
" --scroll-fg: #b3b3b3;\n", | |
"}\n", | |
":root[theme="dark"], :root [data-jp-theme-light="false"]{\n", | |
" --scroll-bg: #3c3c3c;\n", | |
" --scroll-fg: #97e1fb;\n", | |
"}\n", | |
"body {\n", | |
" scrollbar-color: var(--scroll-fg) var(--scroll-bg);\n", | |
"}\n", | |
"body::-webkit-scrollbar {\n", | |
" width: 10px; /* Mostly for vertical scrollbars */\n", | |
" height: 10px; /* Mostly for horizontal scrollbars */\n", | |
"}\n", | |
"body::-webkit-scrollbar-thumb {\n", | |
" background-color: var(--scroll-fg);\n", | |
"}\n", | |
"body::-webkit-scrollbar-track {\n", | |
" background-color: var(--scroll-bg);\n", | |
"}\n", | |
" </style>\n", | |
" </head>\n", | |
" <body>\n", | |
" <table class="dataframe" id="df_1879048206"></table>\n", | |
"\n", | |
"<p class="dataframe_description">DataRow: index = 0, columnsCount = 2</p>\n", | |
"\n", | |
" </body>\n", | |
" <script>\n", | |
" (function () {\n", | |
" window.DataFrame = window.DataFrame || new (function () {\n", | |
" this.addTable = function (df) {\n", | |
" let cols = df.cols;\n", | |
" for (let i = 0; i < cols.length; i++) {\n", | |
" for (let c of cols[i].children) {\n", | |
" cols[c].parent = i;\n", | |
" }\n", | |
" }\n", | |
" df.nrow = 0\n", | |
" for (let i = 0; i < df.cols.length; i++) {\n", | |
" if (df.cols[i].values.length > df.nrow) df.nrow = df.cols[i].values.length\n", | |
" }\n", | |
" if (df.id === df.rootId) {\n", | |
" df.expandedFrames = new Set()\n", | |
" df.childFrames = {}\n", | |
" const table = this.getTableElement(df.id)\n", | |
" table.df = df\n", | |
" for (let i = 0; i < df.cols.length; i++) {\n", | |
" let col = df.cols[i]\n", | |
" if (col.parent === undefined && col.children.length > 0) col.expanded = true\n", | |
" }\n", | |
" } else {\n", | |
" const rootDf = this.getTableData(df.rootId)\n", | |
" rootDf.childFrames[df.id] = df\n", | |
" }\n", | |
" }\n", | |
"\n", | |
" this.computeRenderData = function (df) {\n", | |
" let result = []\n", | |
" let pos = 0\n", | |
" for (let col = 0; col < df.cols.length; col++) {\n", | |
" if (df.cols[col].parent === undefined)\n", | |
" pos += this.computeRenderDataRec(df.cols, col, pos, 0, result, false, false)\n", | |
" }\n", | |
" for (let i = 0; i < result.length; i++) {\n", | |
" let row = result[i]\n", | |
" for (let j = 0; j < row.length; j++) {\n", | |
" let cell = row[j]\n", | |
" if (j === 0)\n", | |
" cell.leftBd = false\n", | |
" if (j < row.length - 1) {\n", | |
" let nextData = row[j + 1]\n", | |
" if (nextData.leftBd) cell.rightBd = true\n", | |
" else if (cell.rightBd) nextData.leftBd = true\n", | |
" } else cell.rightBd = false\n", | |
" }\n", | |
" }\n", | |
" return result\n", | |
" }\n", | |
"\n", | |
" this.computeRenderDataRec = function (cols, colId, pos, depth, result, leftBorder, rightBorder) {\n", | |
" if (result.length === depth) {\n", | |
" const array = [];\n", | |
" if (pos > 0) {\n", | |
" let j = 0\n", | |
" for (let i = 0; j < pos; i++) {\n", | |
" let c = result[depth - 1][i]\n", | |
" j += c.span\n", | |
" let copy = Object.assign({empty: true}, c)\n", | |
" array.push(copy)\n", | |
" }\n", | |
" }\n", | |
" result.push(array)\n", | |
" }\n", | |
" const col = cols[colId];\n", | |
" let size = 0;\n", | |
" if (col.expanded) {\n", | |
" let childPos = pos\n", | |
" for (let i = 0; i < col.children.length; i++) {\n", | |
" let child = col.children[i]\n", | |
" let childLeft = i === 0 && (col.children.length > 1 || leftBorder)\n", | |
" let childRight = i === col.children.length - 1 && (col.children.length > 1 || rightBorder)\n", | |
" let childSize = this.computeRenderDataRec(cols, child, childPos, depth + 1, result, childLeft, childRight)\n", | |
" childPos += childSize\n", | |
" size += childSize\n", | |
" }\n", | |
" } else {\n", | |
" for (let i = depth + 1; i < result.length; i++)\n", | |
" result[i].push({id: colId, span: 1, leftBd: leftBorder, rightBd: rightBorder, empty: true})\n", | |
" size = 1\n", | |
" }\n", | |
" let left = leftBorder\n", | |
" let right = rightBorder\n", | |
" if (size > 1) {\n", | |
" left = true\n", | |
" right = true\n", | |
" }\n", | |
" result[depth].push({id: colId, span: size, leftBd: left, rightBd: right})\n", | |
" return size\n", | |
" }\n", | |
"\n", | |
" this.getTableElement = function (id) {\n", | |
" return document.getElementById("df_" + id)\n", | |
" }\n", | |
"\n", | |
" this.getTableData = function (id) {\n", | |
" return this.getTableElement(id).df\n", | |
" }\n", | |
"\n", | |
" this.createExpander = function (isExpanded) {\n", | |
" const svgNs = "http://www.w3.org/2000/svg"\n", | |
" let svg = document.createElementNS(svgNs, "svg")\n", | |
" svg.classList.add("expanderSvg")\n", | |
" let path = document.createElementNS(svgNs, "path")\n", | |
" if (isExpanded) {\n", | |
" svg.setAttribute("viewBox", "0 -2 8 8")\n", | |
" path.setAttribute("d", "M1 0 l-1 1 4 4 4 -4 -1 -1 -3 3Z")\n", | |
" } else {\n", | |
" svg.setAttribute("viewBox", "-2 0 8 8")\n", | |
" path.setAttribute("d", "M1 0 l-1 1 3 3 -3 3 1 1 4 -4Z")\n", | |
" }\n", | |
" path.setAttribute("fill", "currentColor")\n", | |
" svg.appendChild(path)\n", | |
" return svg\n", | |
" }\n", | |
"\n", | |
" this.renderTable = function (id) {\n", | |
"\n", | |
" let table = this.getTableElement(id)\n", | |
"\n", | |
" if (table === null) return\n", | |
"\n", | |
" table.innerHTML = ""\n", | |
"\n", | |
" let df = table.df\n", | |
" let rootDf = df.rootId === df.id ? df : this.getTableData(df.rootId)\n", | |
"\n", | |
" // header\n", | |
" let header = document.createElement("thead")\n", | |
" table.appendChild(header)\n", | |
"\n", | |
" let renderData = this.computeRenderData(df)\n", | |
" for (let j = 0; j < renderData.length; j++) {\n", | |
" let rowData = renderData[j]\n", | |
" let tr = document.createElement("tr");\n", | |
" let isLastRow = j === renderData.length - 1\n", | |
" header.appendChild(tr);\n", | |
" for (let i = 0; i < rowData.length; i++) {\n", | |
" let cell = rowData[i]\n", | |
" let th = document.createElement("th");\n", | |
" th.setAttribute("colspan", cell.span)\n", | |
" let colId = cell.id\n", | |
" let col = df.cols[colId];\n", | |
" if (!cell.empty) {\n", | |
" if (col.children.length === 0) {\n", | |
" th.innerHTML = col.name\n", | |
" } else {\n", | |
" let link = document.createElement("a")\n", | |
" link.className = "expander"\n", | |
" let that = this\n", | |
" link.onclick = function () {\n", | |
" col.expanded = !col.expanded\n", | |
" that.renderTable(id)\n", | |
" }\n", | |
" link.appendChild(this.createExpander(col.expanded))\n", | |
" link.innerHTML += col.name\n", | |
" th.appendChild(link)\n", | |
" }\n", | |
" }\n", | |
" let classes = (cell.leftBd ? " leftBorder" : "") + (cell.rightBd ? " rightBorder" : "")\n", | |
" if (col.rightAlign)\n", | |
" classes += " rightAlign"\n", | |
" if (isLastRow)\n", | |
" classes += " bottomBorder"\n", | |
" if (classes.length > 0)\n", | |
" th.setAttribute("class", classes)\n", | |
" tr.appendChild(th)\n", | |
" }\n", | |
" }\n", | |
"\n", | |
" // body\n", | |
" let body = document.createElement("tbody")\n", | |
" table.appendChild(body)\n", | |
"\n", | |
" let columns = renderData.pop()\n", | |
" for (let row = 0; row < df.nrow; row++) {\n", | |
" let tr = document.createElement("tr");\n", | |
" body.appendChild(tr)\n", | |
" for (let i = 0; i < columns.length; i++) {\n", | |
" let cell = columns[i]\n", | |
" let td = document.createElement("td");\n", | |
" let colId = cell.id\n", | |
" let col = df.cols[colId]\n", | |
" let classes = (cell.leftBd ? " leftBorder" : "") + (cell.rightBd ? " rightBorder" : "")\n", | |
" if (col.rightAlign)\n", | |
" classes += " rightAlign"\n", | |
" if (classes.length > 0)\n", | |
" td.setAttribute("class", classes)\n", | |
" tr.appendChild(td)\n", | |
" let value = col.values[row]\n", | |
" if (value.frameId !== undefined) {\n", | |
" let frameId = value.frameId\n", | |
" let expanded = rootDf.expandedFrames.has(frameId)\n", | |
" let link = document.createElement("a")\n", | |
" link.className = "expander"\n", | |
" let that = this\n", | |
" link.onclick = function () {\n", | |
" if (rootDf.expandedFrames.has(frameId))\n", | |
" rootDf.expandedFrames.delete(frameId)\n", | |
" else rootDf.expandedFrames.add(frameId)\n", | |
" that.renderTable(id)\n", | |
" }\n", | |
" link.appendChild(this.createExpander(expanded))\n", | |
" link.innerHTML += value.value\n", | |
" if (expanded) {\n", | |
" td.appendChild(link)\n", | |
" td.appendChild(document.createElement("p"))\n", | |
" const childTable = document.createElement("table")\n", | |
" childTable.className = "dataframe"\n", | |
" childTable.id = "df_" + frameId\n", | |
" let childDf = rootDf.childFrames[frameId]\n", | |
" childTable.df = childDf\n", | |
" td.appendChild(childTable)\n", | |
" this.renderTable(frameId)\n", | |
" if (childDf.nrow !== childDf.totalRows) {\n", | |
" const footer = document.createElement("p")\n", | |
" footer.innerText = `... showing only top ${childDf.nrow} of ${childDf.totalRows} rows`\n", | |
" td.appendChild(footer)\n", | |
" }\n", | |
" } else {\n", | |
" td.appendChild(link)\n", | |
" }\n", | |
" } else if (value.style !== undefined) {\n", | |
" td.innerHTML = value.value\n", | |
" td.setAttribute("style", value.style)\n", | |
" } else td.innerHTML = value\n", | |
" this.nodeScriptReplace(td)\n", | |
" }\n", | |
" }\n", | |
" }\n", | |
"\n", | |
" this.nodeScriptReplace = function (node) {\n", | |
" if (this.nodeScriptIs(node) === true) {\n", | |
" node.parentNode.replaceChild(this.nodeScriptClone(node), node);\n", | |
" } else {\n", | |
" let i = -1, children = node.childNodes;\n", | |
" while (++i < children.length) {\n", | |
" this.nodeScriptReplace(children[i]);\n", | |
" }\n", | |
" }\n", | |
"\n", | |
" return node;\n", | |
" }\n", | |
"\n", | |
" this.nodeScriptClone = function (node) {\n", | |
" let script = document.createElement("script");\n", | |
" script.text = node.innerHTML;\n", | |
"\n", | |
" let i = -1, attrs = node.attributes, attr;\n", | |
" while (++i < attrs.length) {\n", | |
" script.setAttribute((attr = attrs[i]).name, attr.value);\n", | |
" }\n", | |
" return script;\n", | |
" }\n", | |
"\n", | |
" this.nodeScriptIs = function (node) {\n", | |
" return node.tagName === 'SCRIPT';\n", | |
" }\n", | |
" })()\n", | |
"\n", | |
" window.call_DataFrame = function (f) {\n", | |
" return f();\n", | |
" };\n", | |
"\n", | |
" let funQueue = window["kotlinQueues"] && window["kotlinQueues"]["DataFrame"];\n", | |
" if (funQueue) {\n", | |
" funQueue.forEach(function (f) {\n", | |
" f();\n", | |
" });\n", | |
" funQueue = [];\n", | |
" }\n", | |
"})()\n", | |
"\n", | |
"/*<!--*/\n", | |
"call_DataFrame(function() { DataFrame.addTable({ cols: [{ name: "<span title=\"age: Int\">age</span>", children: [], rightAlign: true, values: ["<span class=\"formatted\" title=\"\"><span class=\"numbers\">1.107335e+01</span></span>"] }, \n", | |
"{ name: "<span title=\"weight: Int\">weight</span>", children: [], rightAlign: true, values: ["<span class=\"formatted\" title=\"\"><span class=\"numbers\">1.710848e+01</span></span>"] }, \n", | |
"], id: 1879048206, rootId: 1879048206, totalRows: 1 } ) });\n", | |
"/*-->*/\n", | |
"\n", | |
"call_DataFrame(function() { DataFrame.renderTable(1879048206) });\n", | |
"\n", | |
"\n", | |
" </script>\n", | |
" </html>\"></iframe>\n", | |
" <script>\n", | |
" function o_resize_iframe_out_8() {\n", | |
" let elem = document.getElementById(\"iframe_out_8\");\n", | |
" resize_iframe_out_8(elem);\n", | |
" setInterval(resize_iframe_out_8, 5000, elem);\n", | |
" }\n", | |
" function resize_iframe_out_8(el) {\n", | |
" let h = el.contentWindow.document.body.scrollHeight;\n", | |
" el.height = h === 0 ? 0 : h + 41;\n", | |
" }\n", | |
" </script> <html theme='dark'>\n", | |
" <head>\n", | |
" <style type=\"text/css\">\n", | |
" :root {\n", | |
" --background: #fff;\n", | |
" --background-odd: #f5f5f5;\n", | |
" --background-hover: #d9edfd;\n", | |
" --header-text-color: #474747;\n", | |
" --text-color: #848484;\n", | |
" --text-color-dark: #000;\n", | |
" --text-color-medium: #737373;\n", | |
" --text-color-pale: #b3b3b3;\n", | |
" --inner-border-color: #aaa;\n", | |
" --bold-border-color: #000;\n", | |
" --link-color: #296eaa;\n", | |
" --link-color-pale: #296eaa;\n", | |
" --link-hover: #1a466c;\n", | |
"}\n", | |
"\n", | |
":root[theme=\"dark\"], :root [data-jp-theme-light=\"false\"], .dataframe_dark{\n", | |
" --background: #303030;\n", | |
" --background-odd: #3c3c3c;\n", | |
" --background-hover: #464646;\n", | |
" --header-text-color: #dddddd;\n", | |
" --text-color: #b3b3b3;\n", | |
" --text-color-dark: #dddddd;\n", | |
" --text-color-medium: #b2b2b2;\n", | |
" --text-color-pale: #737373;\n", | |
" --inner-border-color: #707070;\n", | |
" --bold-border-color: #777777;\n", | |
" --link-color: #008dc0;\n", | |
" --link-color-pale: #97e1fb;\n", | |
" --link-hover: #00688e;\n", | |
"}\n", | |
"\n", | |
"p.dataframe_description {\n", | |
" color: var(--text-color-dark);\n", | |
"}\n", | |
"\n", | |
"table.dataframe {\n", | |
" font-family: \"Helvetica Neue\", Helvetica, Arial, sans-serif;\n", | |
" font-size: 12px;\n", | |
" background-color: var(--background);\n", | |
" color: var(--text-color-dark);\n", | |
" border: none;\n", | |
" border-collapse: collapse;\n", | |
"}\n", | |
"\n", | |
"table.dataframe th, td {\n", | |
" padding: 6px;\n", | |
" border: 1px solid transparent;\n", | |
" text-align: left;\n", | |
"}\n", | |
"\n", | |
"table.dataframe th {\n", | |
" background-color: var(--background);\n", | |
" color: var(--header-text-color);\n", | |
"}\n", | |
"\n", | |
"table.dataframe td {\n", | |
" vertical-align: top;\n", | |
"}\n", | |
"\n", | |
"table.dataframe th.bottomBorder {\n", | |
" border-bottom-color: var(--bold-border-color);\n", | |
"}\n", | |
"\n", | |
"table.dataframe tbody > tr:nth-child(odd) {\n", | |
" background: var(--background-odd);\n", | |
"}\n", | |
"\n", | |
"table.dataframe tbody > tr:nth-child(even) {\n", | |
" background: var(--background);\n", | |
"}\n", | |
"\n", | |
"table.dataframe tbody > tr:hover {\n", | |
" background: var(--background-hover);\n", | |
"}\n", | |
"\n", | |
"table.dataframe a {\n", | |
" cursor: pointer;\n", | |
" color: var(--link-color);\n", | |
" text-decoration: none;\n", | |
"}\n", | |
"\n", | |
"table.dataframe tr:hover > td a {\n", | |
" color: var(--link-color-pale);\n", | |
"}\n", | |
"\n", | |
"table.dataframe a:hover {\n", | |
" color: var(--link-hover);\n", | |
" text-decoration: underline;\n", | |
"}\n", | |
"\n", | |
"table.dataframe img {\n", | |
" max-width: fit-content;\n", | |
"}\n", | |
"\n", | |
"table.dataframe th.complex {\n", | |
" background-color: var(--background);\n", | |
" border: 1px solid var(--background);\n", | |
"}\n", | |
"\n", | |
"table.dataframe .leftBorder {\n", | |
" border-left-color: var(--inner-border-color);\n", | |
"}\n", | |
"\n", | |
"table.dataframe .rightBorder {\n", | |
" border-right-color: var(--inner-border-color);\n", | |
"}\n", | |
"\n", | |
"table.dataframe .rightAlign {\n", | |
" text-align: right;\n", | |
"}\n", | |
"\n", | |
"table.dataframe .expanderSvg {\n", | |
" width: 8px;\n", | |
" height: 8px;\n", | |
" margin-right: 3px;\n", | |
"}\n", | |
"\n", | |
"table.dataframe .expander {\n", | |
" display: flex;\n", | |
" align-items: center;\n", | |
"}\n", | |
"\n", | |
"/* formatting */\n", | |
"\n", | |
"table.dataframe .null {\n", | |
" color: var(--text-color-pale);\n", | |
"}\n", | |
"\n", | |
"table.dataframe .structural {\n", | |
" color: var(--text-color-medium);\n", | |
" font-weight: bold;\n", | |
"}\n", | |
"\n", | |
"table.dataframe .dataFrameCaption {\n", | |
" font-weight: bold;\n", | |
"}\n", | |
"\n", | |
"table.dataframe .numbers {\n", | |
" color: var(--text-color-dark);\n", | |
"}\n", | |
"\n", | |
"table.dataframe td:hover .formatted .structural, .null {\n", | |
" color: var(--text-color-dark);\n", | |
"}\n", | |
"\n", | |
"table.dataframe tr:hover .formatted .structural, .null {\n", | |
" color: var(--text-color-dark);\n", | |
"}\n", | |
"\n", | |
"\n", | |
" </style>\n", | |
" </head>\n", | |
" <body>\n", | |
" <table class=\"dataframe\" id=\"static_df_1879048207\"><thead><tr><th class=\"bottomBorder\" style=\"text-align:left\">age</th><th class=\"bottomBorder\" style=\"text-align:left\">weight</th></tr></thead><tbody><tr><td style=\"vertical-align:top\">11.073349</td><td style=\"vertical-align:top\">17.108477</td></tr></tbody></table>\n", | |
" </body>\n", | |
" <script>\n", | |
" document.getElementById(\"static_df_1879048207\").style.display = \"none\";\n", | |
" </script>\n", | |
" </html>" | |
], | |
"application/kotlindataframe+json": "{\"$version\":\"2.0.0\",\"metadata\":{\"columns\":[\"age\",\"weight\"],\"nrow\":1,\"ncol\":2},\"kotlin_dataframe\":[{\"age\":11.073348527841414,\"weight\":17.108477430794363}]}" | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"execution_count": 11 | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2024-06-06T13:14:23.920348863Z", | |
"start_time": "2024-06-06T13:14:23.878118903Z" | |
} | |
}, | |
"cell_type": "code", | |
"source": "std.age", | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"class java.lang.Double cannot be cast to class java.lang.Integer (java.lang.Double and java.lang.Integer are in module java.base of loader 'bootstrap')\n", | |
"java.lang.ClassCastException: class java.lang.Double cannot be cast to class java.lang.Integer (java.lang.Double and java.lang.Integer are in module java.base of loader 'bootstrap')\n", | |
"\tat Line_23_jupyter._DataFrameType2_age(Line_23.jupyter.kts:5)\n", | |
"\tat Line_26_jupyter.<init>(Line_26.jupyter.kts:1)\n", | |
"\tat java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)\n", | |
"\tat java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)\n", | |
"\tat java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)\n", | |
"\tat java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)\n", | |
"\tat java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)\n", | |
"\tat kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.evalWithConfigAndOtherScriptsResults(BasicJvmScriptEvaluator.kt:122)\n", | |
"\tat kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.invoke$suspendImpl(BasicJvmScriptEvaluator.kt:48)\n", | |
"\tat kotlin.script.experimental.jvm.BasicJvmScriptEvaluator.invoke(BasicJvmScriptEvaluator.kt)\n", | |
"\tat kotlin.script.experimental.jvm.BasicJvmReplEvaluator.eval(BasicJvmReplEvaluator.kt:49)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.InternalEvaluatorImpl$eval$resultWithDiagnostics$1.invokeSuspend(InternalEvaluatorImpl.kt:127)\n", | |
"\tat kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)\n", | |
"\tat kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104)\n", | |
"\tat kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:277)\n", | |
"\tat kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:95)\n", | |
"\tat kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:69)\n", | |
"\tat kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)\n", | |
"\tat kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:48)\n", | |
"\tat kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.InternalEvaluatorImpl.eval(InternalEvaluatorImpl.kt:127)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.CellExecutorImpl$execute$1$result$1.invoke(CellExecutorImpl.kt:79)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.CellExecutorImpl$execute$1$result$1.invoke(CellExecutorImpl.kt:77)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.ReplForJupyterImpl.withHost(ReplForJupyterImpl.kt:758)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.CellExecutorImpl.execute(CellExecutorImpl.kt:77)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.repl.execution.CellExecutor$DefaultImpls.execute$default(CellExecutor.kt:12)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.ReplForJupyterImpl.evaluateUserCode(ReplForJupyterImpl.kt:581)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.ReplForJupyterImpl.access$evaluateUserCode(ReplForJupyterImpl.kt:136)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.ReplForJupyterImpl$evalEx$1.invoke(ReplForJupyterImpl.kt:439)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.ReplForJupyterImpl$evalEx$1.invoke(ReplForJupyterImpl.kt:436)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.ReplForJupyterImpl.withEvalContext(ReplForJupyterImpl.kt:417)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.repl.impl.ReplForJupyterImpl.evalEx(ReplForJupyterImpl.kt:436)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.messaging.IdeCompatibleMessageRequestProcessor$processExecuteRequest$1$response$1$1.invoke(IdeCompatibleMessageRequestProcessor.kt:140)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.messaging.IdeCompatibleMessageRequestProcessor$processExecuteRequest$1$response$1$1.invoke(IdeCompatibleMessageRequestProcessor.kt:139)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.execution.JupyterExecutorImpl$Task.execute(JupyterExecutorImpl.kt:42)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.execution.JupyterExecutorImpl$executorThread$1.invoke(JupyterExecutorImpl.kt:82)\n", | |
"\tat org.jetbrains.kotlinx.jupyter.execution.JupyterExecutorImpl$executorThread$1.invoke(JupyterExecutorImpl.kt:80)\n", | |
"\tat kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:30)\n" | |
] | |
} | |
], | |
"execution_count": 12 | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "code", | |
"outputs": [], | |
"execution_count": null, | |
"source": "" | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Kotlin", | |
"language": "kotlin", | |
"name": "kotlin" | |
}, | |
"language_info": { | |
"name": "kotlin", | |
"version": "1.9.23", | |
"mimetype": "text/x-kotlin", | |
"file_extension": ".kt", | |
"pygments_lexer": "kotlin", | |
"codemirror_mode": "text/x-kotlin", | |
"nbconvert_exporter": "" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment