From d220dd335060eb7bc965ab2ab031f818b07de7ff Mon Sep 17 00:00:00 2001 From: Nikita Klimenko Date: Thu, 18 Dec 2025 13:27:28 +0200 Subject: [PATCH] Migrate most of the examples in 40 puzzles from delegate style dataframeOf(Columns) to dataFrameOf(Pair) Didn't do it for random-related examples because I'm still not sure about cleanest replacement for these specific cases --- .../notebooks/dev/puzzles/40 puzzles.ipynb | 2287 ++++++++++++----- examples/notebooks/puzzles/40 puzzles.ipynb | 2287 ++++++++++++----- 2 files changed, 3274 insertions(+), 1300 deletions(-) diff --git a/examples/notebooks/dev/puzzles/40 puzzles.ipynb b/examples/notebooks/dev/puzzles/40 puzzles.ipynb index 79a1706620..373a5fc3d9 100644 --- a/examples/notebooks/dev/puzzles/40 puzzles.ipynb +++ b/examples/notebooks/dev/puzzles/40 puzzles.ipynb @@ -22,8 +22,20 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:19:59.395182Z", - "start_time": "2025-09-09T10:19:54.390222Z" + "end_time": "2025-12-18T11:19:41.542631050Z", + "start_time": "2025-12-18T11:19:40.843063224Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_3_jupyter", + "Line_4_jupyter", + "Line_5_jupyter", + "Line_6_jupyter", + "Line_7_jupyter", + "Line_8_jupyter", + "Line_9_jupyter", + "Line_10_jupyter" + ] } }, "cell_type": "code", @@ -41,10 +53,10 @@ "\n", "Consider the following columns:\n", "```[kotlin]\n", - "val animal by columnOf(\"cat\", \"cat\", \"snake\", \"dog\", \"dog\", \"cat\", \"snake\", \"cat\", \"dog\", \"dog\")\n", - "val age by columnOf(2.5, 3.0, 0.5, Double.NaN, 5.0, 2.0, 4.5, Double.NaN, 7, 3)\n", - "val visits by columnOf(1, 3, 2, 3, 2, 3, 1, 1, 2, 1)\n", - "val priority by columnOf(\"yes\", \"yes\", \"no\", \"yes\", \"no\", \"no\", \"no\", \"yes\", \"no\", \"no\")\n", + "columnOf(\"cat\", \"cat\", \"snake\", \"dog\", \"dog\", \"cat\", \"snake\", \"cat\", \"dog\", \"dog\")\n", + "columnOf(2.5, 3.0, 0.5, Double.NaN, 5.0, 2.0, 4.5, Double.NaN, 7, 3)\n", + "columnOf(1, 3, 2, 3, 2, 3, 1, 1, 2, 1)\n", + "columnOf(\"yes\", \"yes\", \"no\", \"yes\", \"no\", \"no\", \"no\", \"yes\", \"no\", \"no\")\n", "```\n", "**2.** Create a DataFrame df from this columns." ] @@ -52,25 +64,32 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:02.727979Z", - "start_time": "2025-09-09T10:19:59.649721Z" + "end_time": "2025-12-18T11:19:42.256463391Z", + "start_time": "2025-12-18T11:19:41.547295069Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_11_jupyter", + "Line_12_jupyter", + "Line_13_jupyter" + ] } }, "cell_type": "code", "source": [ - "val animal by columnOf(\"cat\", \"cat\", \"snake\", \"dog\", \"dog\", \"cat\", \"snake\", \"cat\", \"dog\", \"dog\")\n", - "val age by columnOf(2.5, 3.0, 0.5, Double.NaN, 5.0, 2.0, 4.5, Double.NaN, 7.0, 3.0)\n", - "val visits by columnOf(1, 3, 2, 3, 2, 3, 1, 1, 2, 1)\n", - "val priority by columnOf(\"yes\", \"yes\", \"no\", \"yes\", \"no\", \"no\", \"no\", \"yes\", \"no\", \"no\")\n", - "\n", - "val df = dataFrameOf(animal, age, visits, priority)\n", + "val df = dataFrameOf(\n", + " \"animal\" to columnOf(\"cat\", \"cat\", \"snake\", \"dog\", \"dog\", \"cat\", \"snake\", \"cat\", \"dog\", \"dog\"),\n", + " \"age\" to columnOf(2.5, 3.0, 0.5, Double.NaN, 5.0, 2.0, 4.5, Double.NaN, 7.0, 3.0),\n", + " \"visits\" to columnOf(1, 3, 2, 3, 2, 3, 1, 1, 2, 1),\n", + " \"priority\" to columnOf(\"yes\", \"yes\", \"no\", \"yes\", \"no\", \"no\", \"no\", \"yes\", \"no\", \"no\"),\n", + ")\n", "df" ], "outputs": [ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
animalagevisitspriority
cat2.5000001yes
cat3.0000003yes
snake0.5000002no
\n", + "
animalagevisitspriority
cat2.5000001yes
cat3.0000003yes
snake0.5000002no
\n", " \n", " \n", " " ], @@ -2128,17 +2162,22 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:07.907697Z", - "start_time": "2025-09-09T10:20:07.711736Z" + "end_time": "2025-12-18T11:19:43.547372659Z", + "start_time": "2025-12-18T11:19:43.339126731Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_20_jupyter" + ] } }, "cell_type": "code", - "source": "df[animal, age]", + "source": "df.select { animal and age }", "outputs": [ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
animalage
dogNaN
dog5.000000
dog7.000000
\n", + "
animalage
dogNaN
dog5.000000
dog7.000000
\n", " \n", " \n", " " ], @@ -3472,8 +3516,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:10.601401Z", - "start_time": "2025-09-09T10:20:10.368239Z" + "end_time": "2025-12-18T11:19:44.130666181Z", + "start_time": "2025-12-18T11:19:43.890826650Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_24_jupyter" + ] } }, "cell_type": "code", @@ -3482,7 +3531,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
animalagevisitspriority
dogNaN3yes
catNaN1yes
\n", + "
animalagevisitspriority
dogNaN3yes
catNaN1yes
\n", " \n", " \n", " " ], @@ -4820,8 +4874,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:13.067840Z", - "start_time": "2025-09-09T10:20:12.870865Z" + "end_time": "2025-12-18T11:19:44.731860002Z", + "start_time": "2025-12-18T11:19:44.516203139Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_28_jupyter" + ] } }, "cell_type": "code", @@ -4830,7 +4889,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
animalagevisitspriority
cat2.5000001yes
cat3.0000003yes
cat2.0000003no
dog3.0000001no
\n", + "
animalagevisitspriority
cat2.5000001yes
cat3.0000003yes
cat2.0000003no
dog3.0000001no
\n", " \n", " \n", " " ], @@ -6168,8 +6232,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:15.695961Z", - "start_time": "2025-09-09T10:20:15.204861Z" + "end_time": "2025-12-18T11:19:45.321374555Z", + "start_time": "2025-12-18T11:19:45.119529698Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_32_jupyter" + ] } }, "cell_type": "code", @@ -6178,7 +6247,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
animalagevisitspriority
cat2.5000001yes
cat3.0000003yes
snake0.5000002no
dogNaN3yes
dog5.0000002no
cat2.0000003no
snake4.5000001no
catNaN1yes
dog7.0000002no
dog3.0000001no
\n", + "
animalagevisitspriority
cat2.5000001yes
cat3.0000003yes
snake0.5000002no
dogNaN3yes
dog5.0000002no
cat2.0000003no
snake4.5000001no
catNaN1yes
dog7.0000002no
dog3.0000001no
\n", " \n", " \n", " " ], @@ -8219,8 +8303,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:19.769933Z", - "start_time": "2025-09-09T10:20:19.591996Z" + "end_time": "2025-12-18T11:19:46.367888372Z", + "start_time": "2025-12-18T11:19:46.058158419Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_39_jupyter" + ] } }, "cell_type": "code", @@ -8229,7 +8318,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
animalagevisitspriority
catNaN1yes
dogNaN3yes
dog7.0000002no
dog5.0000002no
snake4.5000001no
dog3.0000001no
cat3.0000003yes
cat2.5000001yes
cat2.0000003no
snake0.5000002no
\n", + "
animalagevisitspriority
catNaN1yes
dogNaN3yes
dog7.0000002no
dog5.0000002no
snake4.5000001no
dog3.0000001no
cat3.0000003yes
cat2.5000001yes
cat2.0000003no
snake0.5000002no
\n", " \n", " \n", " " ], @@ -9565,8 +9659,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:22.589698Z", - "start_time": "2025-09-09T10:20:22.375775Z" + "end_time": "2025-12-18T11:19:46.937073806Z", + "start_time": "2025-12-18T11:19:46.722579483Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_43_jupyter" + ] } }, "cell_type": "code", @@ -9575,7 +9674,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
animalagevisitspriority
cat2.5000001yes
cat3.0000003yes
snake0.5000002no
corgiNaN3yes
corgi5.0000002no
cat2.0000003no
snake4.5000001no
catNaN1yes
corgi7.0000002no
corgi3.0000001no
\n", + "
animalagevisitspriority
cat2.5000001yes
cat3.0000003yes
snake0.5000002no
corgiNaN3yes
corgi5.0000002no
cat2.0000003no
snake4.5000001no
catNaN1yes
corgi7.0000002no
corgi3.0000001no
\n", " \n", " \n", " " ], @@ -10917,8 +11021,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:24.572846Z", - "start_time": "2025-09-09T10:20:24.294243Z" + "end_time": "2025-12-18T11:19:47.538227593Z", + "start_time": "2025-12-18T11:19:47.243994037Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_47_jupyter" + ] } }, "cell_type": "code", @@ -10927,7 +11036,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
A
1
2
2
3
4
5
5
5
6
7
7
\n", + "
A
1
2
2
3
4
5
5
5
6
7
7
\n", " \n", " \n", " " ], @@ -12284,8 +12400,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:26.967333Z", - "start_time": "2025-09-09T10:20:26.811413Z" + "end_time": "2025-12-18T11:19:48.106029432Z", + "start_time": "2025-12-18T11:19:47.883015099Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_53_jupyter" + ] } }, "cell_type": "code", @@ -12294,7 +12415,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
A
1
2
3
4
5
6
7
\n", + "
A
1
2
3
4
5
6
7
\n", " \n", " \n", " " ], @@ -13621,8 +13747,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:29.315966Z", - "start_time": "2025-09-09T10:20:29.209502Z" + "end_time": "2025-12-18T11:19:48.524516883Z", + "start_time": "2025-12-18T11:19:48.428439626Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_57_jupyter" + ] } }, "cell_type": "code", @@ -13631,7 +13762,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
abcdefghij
0.2009070.8871910.2549470.3881570.9087650.3296940.9522780.2858200.0136360.095965
0.7569150.0644090.7341920.1102490.5909990.7049050.9120190.6520980.0368660.420558
0.7711180.9882530.5219260.7316640.0221420.6355320.7668380.8530870.9068440.446849
0.2618270.7294400.2094040.6021790.8475070.7304870.1263330.5451070.7954820.378680
0.7529580.3208140.7202080.7671470.5972440.0576180.1913100.2033210.9037600.523245
\n", + "
abcdefghij
0.8419110.2821870.5048440.3160490.4903500.5932060.5507190.8143400.0890810.113149
0.4982080.8476610.2279870.5182300.1260700.6163240.1471160.2624630.3235520.737167
0.7889160.1624580.1833110.9265850.4297270.7407670.9306180.9710540.8023080.230486
0.5533470.4825940.4054610.3698490.4315320.1778260.4652870.2624960.2016740.430214
0.8749320.1620430.4775250.8840590.2925860.8548660.4564860.5893030.1404260.911116
\n", " \n", " \n", " " ], - "application/kotlindataframe+json": "{\"$version\":\"2.2.0\",\"metadata\":{\"columns\":[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"}],\"nrow\":5,\"ncol\":10,\"is_formatted\":false},\"kotlin_dataframe\":[{\"a\":0.20090685064331937,\"b\":0.8871912255133791,\"c\":0.2549468111321541,\"d\":0.38815694631380127,\"e\":0.9087653789721286,\"f\":0.3296938927440395,\"g\":0.9522777703806122,\"h\":0.2858200144042208,\"i\":0.013636055573945094,\"j\":0.09596530470652986},{\"a\":0.7569150749029241,\"b\":0.06440905190823076,\"c\":0.7341915384170767,\"d\":0.11024863730405987,\"e\":0.590999032572314,\"f\":0.7049045211724224,\"g\":0.9120191694445311,\"h\":0.6520979901678069,\"i\":0.036866394726266294,\"j\":0.42055787198537553},{\"a\":0.7711179884037822,\"b\":0.9882529014691451,\"c\":0.5219260940599081,\"d\":0.7316640236098008,\"e\":0.02214156003644352,\"f\":0.6355322467903455,\"g\":0.7668379494838335,\"h\":0.8530872406235399,\"i\":0.9068442102269314,\"j\":0.44684852264187824},{\"a\":0.26182665083165513,\"b\":0.7294403477511925,\"c\":0.2094035232312974,\"d\":0.6021794872113193,\"e\":0.8475066241565566,\"f\":0.7304873105946014,\"g\":0.12633259066356395,\"h\":0.5451066654099072,\"i\":0.7954819015909015,\"j\":0.378679721185631},{\"a\":0.7529584519095024,\"b\":0.3208139103643325,\"c\":0.7202083013432629,\"d\":0.767147363074108,\"e\":0.5972443068782157,\"f\":0.05761833328160326,\"g\":0.19130970715775053,\"h\":0.20332141649523094,\"i\":0.9037601846779532,\"j\":0.5232454636011823}]}" + "application/kotlindataframe+json": "{\"$version\":\"2.2.0\",\"metadata\":{\"columns\":[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"}],\"nrow\":5,\"ncol\":10,\"is_formatted\":false},\"kotlin_dataframe\":[{\"a\":0.8419114160124052,\"b\":0.282186920782716,\"c\":0.5048443177170018,\"d\":0.31604901017535125,\"e\":0.4903503697680932,\"f\":0.5932062822034694,\"g\":0.5507189032521874,\"h\":0.8143400642944842,\"i\":0.0890806635407565,\"j\":0.11314865188165824},{\"a\":0.49820844533063235,\"b\":0.8476612083057321,\"c\":0.22798742360150803,\"d\":0.5182296202669303,\"e\":0.12607036482076805,\"f\":0.6163241622452882,\"g\":0.1471161686192296,\"h\":0.26246326600812764,\"i\":0.32355220762629744,\"j\":0.7371668074893234},{\"a\":0.788915937670967,\"b\":0.16245843051774012,\"c\":0.18331082327972492,\"d\":0.9265848824100162,\"e\":0.4297273634305062,\"f\":0.7407665914938036,\"g\":0.9306177608421328,\"h\":0.9710544319125589,\"i\":0.802308385674185,\"j\":0.23048565019517087},{\"a\":0.553347476141766,\"b\":0.48259411048976075,\"c\":0.40546089768988547,\"d\":0.3698490765337128,\"e\":0.43153183270372275,\"f\":0.17782580998707898,\"g\":0.465287247289943,\"h\":0.2624963066894521,\"i\":0.20167375143620148,\"j\":0.43021369129837617},{\"a\":0.8749319981380302,\"b\":0.16204312466903636,\"c\":0.4775248119116894,\"d\":0.8840586021809772,\"e\":0.2925857979551013,\"f\":0.8548662347706445,\"g\":0.4564858905910003,\"h\":0.5893027524048042,\"i\":0.1404261330157901,\"j\":0.911116058678073}]}" }, "execution_count": 27, "metadata": {}, @@ -16333,8 +16483,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:34.365240Z", - "start_time": "2025-09-09T10:20:34.058803Z" + "end_time": "2025-12-18T11:19:50.235988942Z", + "start_time": "2025-12-18T11:19:49.987687771Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_69_jupyter" + ] } }, "cell_type": "code", @@ -16343,7 +16498,7 @@ { "data": { "text/plain": [ - "j" + "i" ] }, "execution_count": 28, @@ -16361,8 +16516,15 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:35.327978Z", - "start_time": "2025-09-09T10:20:34.825964Z" + "end_time": "2025-12-18T11:19:50.387907271Z", + "start_time": "2025-12-18T11:19:50.238960093Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_70_jupyter", + "Line_71_jupyter", + "Line_72_jupyter" + ] } }, "cell_type": "code", @@ -16374,7 +16536,7 @@ { "data": { "text/plain": [ - "18" + "19" ] }, "execution_count": 29, @@ -16398,8 +16560,15 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:36.465361Z", - "start_time": "2025-09-09T10:20:35.654021Z" + "end_time": "2025-12-18T11:19:50.641509850Z", + "start_time": "2025-12-18T11:19:50.391210050Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_73_jupyter", + "Line_74_jupyter", + "Line_75_jupyter" + ] } }, "cell_type": "code", @@ -16420,7 +16589,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
res
e
c
d
h
d
\n", + "
res
e
c
d
h
d
\n", " \n", " \n", " " ], @@ -17760,10 +17934,10 @@ "source": [ "**25.** A DataFrame has a column of groups 'grps' and a column of integer values 'vals':\n", "```kotlin\n", - "val grps by column(\"a\", \"a\", \"a\", \"b\", \"b\", \"c\", \"a\", \"a\", \"b\", \"c\", \"c\", \"c\", \"b\", \"b\", \"c\")\n", - "val vals by column(12, 345, 3, 1, 45, 14, 4, 52, 54, 23, 235, 21, 57, 3, 87)\n", - "\n", - "val df = dataFrameOf(grps, vals)\n", + "val df = dataFrameOf(\n", + " \"grps\" to columnOf(\"a\", \"a\", \"a\", \"b\", \"b\", \"c\", \"a\", \"a\", \"b\", \"c\", \"c\", \"c\", \"b\", \"b\", \"c\"),\n", + " \"vals\" to columnOf(12, 345, 3, 1, 45, 14, 4, 52, 54, 23, 235, 21, 57, 3, 87),\n", + ")\n", "```\n", "\n", "For each group, find the sum of the three greatest values. You should end up with the answer as follows:\n", @@ -17778,23 +17952,30 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:39.631818Z", - "start_time": "2025-09-09T10:20:38.996891Z" + "end_time": "2025-12-18T11:19:51.467157852Z", + "start_time": "2025-12-18T11:19:51.142193506Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_79_jupyter", + "Line_80_jupyter", + "Line_81_jupyter" + ] } }, "cell_type": "code", "source": [ - "val grps by columnOf(\"a\", \"a\", \"a\", \"b\", \"b\", \"c\", \"a\", \"a\", \"b\", \"c\", \"c\", \"c\", \"b\", \"b\", \"c\")\n", - "val vals by columnOf(12, 345, 3, 1, 45, 14, 4, 52, 54, 23, 235, 21, 57, 3, 87)\n", - "\n", - "val df = dataFrameOf(grps, vals)\n", + "val df = dataFrameOf(\n", + " \"grps\" to columnOf(\"a\", \"a\", \"a\", \"b\", \"b\", \"c\", \"a\", \"a\", \"b\", \"c\", \"c\", \"c\", \"b\", \"b\", \"c\"),\n", + " \"vals\" to columnOf(12, 345, 3, 1, 45, 14, 4, 52, 54, 23, 235, 21, 57, 3, 87),\n", + ")\n", "df" ], "outputs": [ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
grpsvals
a12
a345
a3
b1
b45
c14
a4
a52
b54
c23
c235
c21
b57
b3
c87
\n", + "
grpsvals
a12
a345
a3
b1
b45
c14
a4
a52
b54
c23
c235
c21
b57
b3
c87
\n", " \n", " \n", " " ], @@ -18451,8 +18632,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:40.958555Z", - "start_time": "2025-09-09T10:20:40.712890Z" + "end_time": "2025-12-18T11:19:51.874156449Z", + "start_time": "2025-12-18T11:19:51.536795229Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_83_jupyter" + ] } }, "cell_type": "code", @@ -18465,7 +18651,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
AB
3441
423
4233
2241
7088
5368
804
5959
451
2714
708
1152
5160
4643
1717
1742
5629
5849
487
7352
\n", + "
AB
3441
423
4233
2241
7088
5368
804
5959
451
2714
708
1152
5160
4643
1717
1742
5629
5849
487
7352
\n", " \n", " \n", " " ], @@ -19821,8 +20014,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:43.816621Z", - "start_time": "2025-09-09T10:20:43.416356Z" + "end_time": "2025-12-18T11:19:52.799510118Z", + "start_time": "2025-12-18T11:19:52.372865385Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_89_jupyter" + ] } }, "cell_type": "code", @@ -19835,7 +20033,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
X
7
2
0
3
4
2
5
0
3
4
\n", + "
X
7
2
0
3
4
2
5
0
3
4
\n", " \n", " \n", " " ], @@ -21189,8 +21394,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:46.239893Z", - "start_time": "2025-09-09T10:20:46.023751Z" + "end_time": "2025-12-18T11:19:53.552737696Z", + "start_time": "2025-12-18T11:19:53.347104241Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_95_jupyter" + ] } }, "cell_type": "code", @@ -21203,7 +21413,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
Y
1
2
0
1
2
3
4
0
1
2
\n", + "
Y
1
2
0
1
2
3
4
0
1
2
\n", " \n", " \n", " " ], @@ -21873,8 +22083,15 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:47.723910Z", - "start_time": "2025-09-09T10:20:46.986249Z" + "end_time": "2025-12-18T11:19:54.071017006Z", + "start_time": "2025-12-18T11:19:53.641692715Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_97_jupyter", + "Line_98_jupyter", + "Line_99_jupyter" + ] } }, "cell_type": "code", @@ -21889,7 +22106,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
abcdefgh
4388661009597423
6634358485925
4959100522811981
9241135728976339
459726550351431
5574336617398038
186491398055652
197675183297132
\n", + "
abcdefgh
4388661009597423
6634358485925
4959100522811981
9241135728976339
459726550351431
5574336617398038
186491398055652
197675183297132
\n", " \n", " \n", " " ], @@ -22552,8 +22769,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:49.199193Z", - "start_time": "2025-09-09T10:20:48.654185Z" + "end_time": "2025-12-18T11:19:54.475257403Z", + "start_time": "2025-12-18T11:19:54.139804923Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_101_jupyter" + ] } }, "cell_type": "code", @@ -22566,7 +22788,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
valsgrps
-17B
-7B
16A
28B
9A
16B
-21B
-14A
-19A
-22A
19B
-2B
-1A
-19B
23A
\n", + "
valsgrps
-17B
-7B
16A
28B
9A
16B
-21B
-14A
-19A
-22A
19B
-2B
-1A
-19B
23A
\n", " \n", " \n", " " ], @@ -23937,8 +24166,15 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:52.921344Z", - "start_time": "2025-09-09T10:20:51.977826Z" + "end_time": "2025-12-18T11:19:55.629440336Z", + "start_time": "2025-12-18T11:19:55.172126724Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_107_jupyter", + "Line_108_jupyter", + "Line_109_jupyter" + ] } }, "cell_type": "code", @@ -23955,7 +24191,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
valsgrpspatched_values
-17B21.000000
-7B21.000000
16A16.000000
28B28.000000
9A9.000000
16B16.000000
-21B21.000000
-14A16.000000
-19A16.000000
-22A16.000000
19B19.000000
-2B21.000000
-1A16.000000
-19B21.000000
23A23.000000
\n", + "
valsgrpspatched_values
-17B21.000000
-7B21.000000
16A16.000000
28B28.000000
9A9.000000
16B16.000000
-21B21.000000
-14A16.000000
-19A16.000000
-22A16.000000
19B19.000000
-2B21.000000
-1A16.000000
-19B21.000000
23A23.000000
\n", " \n", " \n", " " ], @@ -24616,10 +24852,10 @@ "source": [ "**30.** Implement a rolling mean over groups with window size 3, which ignores NaN value. For example, consider the following DataFrame:\n", "```kotlin\n", - "val group by columnOf(\"a\", \"a\", \"b\", \"b\", \"a\", \"b\", \"b\", \"b\", \"a\", \"b\", \"a\", \"b\")\n", - "val value by columnOf(1.0, 2.0, 3.0, Double.NaN, 2.0, 3.0, Double.NaN, 1.0, 7.0, 3.0, Double.NaN, 8.0)\n", - "\n", - "val df = dataFrameOf(group, value)\n", + "val df = dataFrameOf(\n", + " \"groups\" to columnOf(\"a\", \"a\", \"b\", \"b\", \"a\", \"b\", \"b\", \"b\", \"a\", \"b\", \"a\", \"b\"),\n", + " \"value\" to columnOf(1.0, 2.0, 3.0, Double.NaN, 2.0, 3.0, Double.NaN, 1.0, 7.0, 3.0, Double.NaN, 8.0),\n", + ")\n", "df\n", "\n", "group value\n", @@ -24658,23 +24894,30 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:55.956419Z", - "start_time": "2025-09-09T10:20:54.685746Z" + "end_time": "2025-12-18T11:19:56.047538523Z", + "start_time": "2025-12-18T11:19:55.719618410Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_111_jupyter", + "Line_112_jupyter", + "Line_113_jupyter" + ] } }, "cell_type": "code", "source": [ - "val groups by columnOf(\"a\", \"a\", \"b\", \"b\", \"a\", \"b\", \"b\", \"b\", \"a\", \"b\", \"a\", \"b\")\n", - "val value by columnOf(1.0, 2.0, 3.0, Double.NaN, 2.0, 3.0, Double.NaN, 1.0, 7.0, 3.0, Double.NaN, 8.0)\n", - "\n", - "val df = dataFrameOf(groups, value)\n", + "val df = dataFrameOf(\n", + " \"groups\" to columnOf(\"a\", \"a\", \"b\", \"b\", \"a\", \"b\", \"b\", \"b\", \"a\", \"b\", \"a\", \"b\"),\n", + " \"value\" to columnOf(1.0, 2.0, 3.0, Double.NaN, 2.0, 3.0, Double.NaN, 1.0, 7.0, 3.0, Double.NaN, 8.0),\n", + ")\n", "df" ], "outputs": [ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
groupsvalueres
a1.0000001.000000
a2.0000001.500000
b3.0000003.000000
bNaN3.000000
a2.0000001.666667
b3.0000003.000000
bNaN3.000000
b1.0000002.000000
a7.0000003.666667
b3.0000002.000000
aNaN4.500000
b8.0000004.000000
\n", + "
groupsvalueres
a1.0000001.000000
a2.0000001.500000
b3.0000003.000000
bNaN3.000000
a2.0000001.666667
b3.0000003.000000
bNaN3.000000
b1.0000002.000000
a7.0000003.666667
b3.0000002.000000
aNaN4.500000
b8.0000004.000000
\n", " \n", " \n", " " ], @@ -26019,8 +26267,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:58.558932Z", - "start_time": "2025-09-09T10:20:58.505722Z" + "end_time": "2025-12-18T11:19:56.754450953Z", + "start_time": "2025-12-18T11:19:56.683121372Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_117_jupyter" + ] } }, "cell_type": "code", @@ -26031,8 +26284,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:21:00.685365Z", - "start_time": "2025-09-09T10:20:59.536462Z" + "end_time": "2025-12-18T11:19:57.126047058Z", + "start_time": "2025-12-18T11:19:56.791536294Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_118_jupyter" + ] } }, "cell_type": "code", @@ -26078,8 +26336,15 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:21:02.442214Z", - "start_time": "2025-09-09T10:21:01.069826Z" + "end_time": "2025-12-18T11:19:57.565043672Z", + "start_time": "2025-12-18T11:19:57.140265113Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_119_jupyter", + "Line_120_jupyter", + "Line_121_jupyter" + ] } }, "cell_type": "code", @@ -26089,16 +26354,17 @@ "\n", "val days = (start..end).toList()\n", "\n", - "val dti = days.toColumn(\"dti\")\n", - "val s = List(dti.size()) { Random.nextDouble() }.toColumn(\"s\")\n", - "val df = dataFrameOf(dti, s)\n", + "val df = dataFrameOf(\n", + " \"dti\" to days.toColumn(),\n", + " \"s\" to List(days.size) { Random.nextDouble() }.toColumn()\n", + ")\n", "df.head()" ], "outputs": [ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
month4max
dtismonth4
12015-04-200.9961421
22015-07-220.9963762
32015-09-150.9984813
\n", + "
month4max
dtismonth4
12015-03-220.9982801
22015-05-140.9914552
32015-12-160.9998913
\n", " \n", " \n", " " ], - "application/kotlindataframe+json": "{\"$version\":\"2.2.0\",\"metadata\":{\"columns\":[\"month4\",\"max\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ColumnGroup\"}],\"nrow\":3,\"ncol\":2,\"is_formatted\":false},\"kotlin_dataframe\":[{\"month4\":1,\"max\":{\"data\":{\"dti\":\"2015-04-20\",\"s\":0.996142449438107,\"month4\":1},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"dti\",\"s\",\"month4\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlinx.datetime.LocalDate\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"month4\":2,\"max\":{\"data\":{\"dti\":\"2015-07-22\",\"s\":0.9963756973660238,\"month4\":2},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"dti\",\"s\",\"month4\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlinx.datetime.LocalDate\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"month4\":3,\"max\":{\"data\":{\"dti\":\"2015-09-15\",\"s\":0.9984806388730291,\"month4\":3},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"dti\",\"s\",\"month4\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlinx.datetime.LocalDate\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}}]}" + "application/kotlindataframe+json": "{\"$version\":\"2.2.0\",\"metadata\":{\"columns\":[\"month4\",\"max\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ColumnGroup\"}],\"nrow\":3,\"ncol\":2,\"is_formatted\":false},\"kotlin_dataframe\":[{\"month4\":1,\"max\":{\"data\":{\"dti\":\"2015-03-22\",\"s\":0.9982800125376523,\"month4\":1},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"dti\",\"s\",\"month4\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlinx.datetime.LocalDate\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"month4\":2,\"max\":{\"data\":{\"dti\":\"2015-05-14\",\"s\":0.9914549696180743,\"month4\":2},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"dti\",\"s\",\"month4\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlinx.datetime.LocalDate\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"month4\":3,\"max\":{\"data\":{\"dti\":\"2015-12-16\",\"s\":0.9998914835120076,\"month4\":3},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"dti\",\"s\",\"month4\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlinx.datetime.LocalDate\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}}]}" }, "execution_count": 49, "metadata": {}, @@ -28143,8 +28424,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:21:06.740021Z", - "start_time": "2025-09-09T10:21:06.693834Z" + "end_time": "2025-12-18T11:19:58.720573737Z", + "start_time": "2025-12-18T11:19:58.641394272Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_128_jupyter" + ] } }, "cell_type": "code", @@ -28158,8 +28444,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:21:08.229904Z", - "start_time": "2025-09-09T10:21:07.618142Z" + "end_time": "2025-12-18T11:19:59.016056372Z", + "start_time": "2025-12-18T11:19:58.722834006Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_129_jupyter" + ] } }, "cell_type": "code", @@ -28176,7 +28467,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
From_ToFlightNumberRecentDelaysAirline
LoNDon_paris10045.000000[23, 47]KLM(!)
MAdrid_miLANNaN[ ]{Air France} (12)
londON_StockhOlm10065.000000[24, 43, 87](British Airways. )
Budapest_PaRisNaN[13]12. Air France
Brussels_londOn10085.000000[67, 32]'Swiss Air'
\n", + "
From_ToFlightNumberRecentDelaysAirline
LoNDon_paris10045.000000[23, 47]KLM(!)
MAdrid_miLANNaN[ ]{Air France} (12)
londON_StockhOlm10065.000000[24, 43, 87](British Airways. )
Budapest_PaRisNaN[13]12. Air France
Brussels_londOn10085.000000[67, 32]'Swiss Air'
\n", " \n", " \n", " " ], @@ -29549,8 +29847,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:21:11.999406Z", - "start_time": "2025-09-09T10:21:11.582393Z" + "end_time": "2025-12-18T11:20:00.173798942Z", + "start_time": "2025-12-18T11:19:59.836065273Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_135_jupyter" + ] } }, "cell_type": "code", @@ -29564,7 +29867,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
FromToFlightNumberRecentDelaysAirline
LoNDonparis10045[23, 47]KLM(!)
MAdridmiLAN10055[ ]{Air France} (12)
londONStockhOlm10065[24, 43, 87](British Airways. )
BudapestPaRis10075[13]12. Air France
BrusselslondOn10085[67, 32]'Swiss Air'
\n", + "
FromToFlightNumberRecentDelaysAirline
LoNDonparis10045[23, 47]KLM(!)
MAdridmiLAN10055[ ]{Air France} (12)
londONStockhOlm10065[24, 43, 87](British Airways. )
BudapestPaRis10075[13]12. Air France
BrusselslondOn10085[67, 32]'Swiss Air'
\n", " \n", " \n", " " ], @@ -30914,8 +31224,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:21:14.533957Z", - "start_time": "2025-09-09T10:21:14.142724Z" + "end_time": "2025-12-18T11:20:00.993293322Z", + "start_time": "2025-12-18T11:20:00.698864044Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_141_jupyter" + ] } }, "cell_type": "code", @@ -30927,7 +31242,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
FromToFlightNumberRecentDelaysAirline
LondonParis10045[23, 47]KLM
MadridMilan10055[ ]Air France
LondonStockholm10065[24, 43, 87]British Airways
BudapestParis10075[13] Air France
BrusselsLondon10085[67, 32]Swiss Air
\n", + "
FromToFlightNumberRecentDelaysAirline
LondonParis10045[23, 47]KLM
MadridMilan10055[ ]Air France
LondonStockholm10065[24, 43, 87]British Airways
BudapestParis10075[13] Air France
BrusselsLondon10085[67, 32]Swiss Air
\n", " \n", " \n", " " ], @@ -32281,20 +32601,27 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:21:17.414060Z", - "start_time": "2025-09-09T10:21:16.638036Z" + "end_time": "2025-12-18T11:20:01.740439057Z", + "start_time": "2025-12-18T11:20:01.448232137Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_145_jupyter", + "Line_146_jupyter", + "Line_147_jupyter" + ] } }, "cell_type": "code", "source": [ - "val prep_df = df2.split { RecentDelays }.into { \"delay_$it\" }\n", - "prep_df" + "val cleanDf = df2.split { RecentDelays }.into { \"delay_$it\" }\n", + "cleanDf" ], "outputs": [ { "data": { "text/html": [ - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
fromtoflightNumberdelay1delay2delay3airline
LondonParis100452347nullKLM
MadridMilan10055nullnullnullAir France
LondonStockholm10065244387British Airways
BudapestParis1007513nullnull Air France
BrusselsLondon100856732nullSwiss Air
\n", + " \n", + " \n", + " " + ], + "application/kotlindataframe+json": "{\"$version\":\"2.2.0\",\"metadata\":{\"columns\":[\"from\",\"to\",\"flightNumber\",\"delay1\",\"delay2\",\"delay3\",\"airline\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int?\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int?\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int?\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"}],\"nrow\":5,\"ncol\":7,\"is_formatted\":false},\"kotlin_dataframe\":[{\"from\":\"London\",\"to\":\"Paris\",\"flightNumber\":10045,\"delay1\":23,\"delay2\":47,\"delay3\":null,\"airline\":\"KLM\"},{\"from\":\"Madrid\",\"to\":\"Milan\",\"flightNumber\":10055,\"delay1\":null,\"delay2\":null,\"delay3\":null,\"airline\":\"Air France\"},{\"from\":\"London\",\"to\":\"Stockholm\",\"flightNumber\":10065,\"delay1\":24,\"delay2\":43,\"delay3\":87,\"airline\":\"British Airways\"},{\"from\":\"Budapest\",\"to\":\"Paris\",\"flightNumber\":10075,\"delay1\":13,\"delay2\":null,\"delay3\":null,\"airline\":\" Air France\"},{\"from\":\"Brussels\",\"to\":\"London\",\"flightNumber\":10085,\"delay1\":67,\"delay2\":32,\"delay3\":null,\"airline\":\"Swiss Air\"}]}" + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "execution_count": 58 } ], "metadata": { diff --git a/examples/notebooks/puzzles/40 puzzles.ipynb b/examples/notebooks/puzzles/40 puzzles.ipynb index 79a1706620..373a5fc3d9 100644 --- a/examples/notebooks/puzzles/40 puzzles.ipynb +++ b/examples/notebooks/puzzles/40 puzzles.ipynb @@ -22,8 +22,20 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:19:59.395182Z", - "start_time": "2025-09-09T10:19:54.390222Z" + "end_time": "2025-12-18T11:19:41.542631050Z", + "start_time": "2025-12-18T11:19:40.843063224Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_3_jupyter", + "Line_4_jupyter", + "Line_5_jupyter", + "Line_6_jupyter", + "Line_7_jupyter", + "Line_8_jupyter", + "Line_9_jupyter", + "Line_10_jupyter" + ] } }, "cell_type": "code", @@ -41,10 +53,10 @@ "\n", "Consider the following columns:\n", "```[kotlin]\n", - "val animal by columnOf(\"cat\", \"cat\", \"snake\", \"dog\", \"dog\", \"cat\", \"snake\", \"cat\", \"dog\", \"dog\")\n", - "val age by columnOf(2.5, 3.0, 0.5, Double.NaN, 5.0, 2.0, 4.5, Double.NaN, 7, 3)\n", - "val visits by columnOf(1, 3, 2, 3, 2, 3, 1, 1, 2, 1)\n", - "val priority by columnOf(\"yes\", \"yes\", \"no\", \"yes\", \"no\", \"no\", \"no\", \"yes\", \"no\", \"no\")\n", + "columnOf(\"cat\", \"cat\", \"snake\", \"dog\", \"dog\", \"cat\", \"snake\", \"cat\", \"dog\", \"dog\")\n", + "columnOf(2.5, 3.0, 0.5, Double.NaN, 5.0, 2.0, 4.5, Double.NaN, 7, 3)\n", + "columnOf(1, 3, 2, 3, 2, 3, 1, 1, 2, 1)\n", + "columnOf(\"yes\", \"yes\", \"no\", \"yes\", \"no\", \"no\", \"no\", \"yes\", \"no\", \"no\")\n", "```\n", "**2.** Create a DataFrame df from this columns." ] @@ -52,25 +64,32 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:02.727979Z", - "start_time": "2025-09-09T10:19:59.649721Z" + "end_time": "2025-12-18T11:19:42.256463391Z", + "start_time": "2025-12-18T11:19:41.547295069Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_11_jupyter", + "Line_12_jupyter", + "Line_13_jupyter" + ] } }, "cell_type": "code", "source": [ - "val animal by columnOf(\"cat\", \"cat\", \"snake\", \"dog\", \"dog\", \"cat\", \"snake\", \"cat\", \"dog\", \"dog\")\n", - "val age by columnOf(2.5, 3.0, 0.5, Double.NaN, 5.0, 2.0, 4.5, Double.NaN, 7.0, 3.0)\n", - "val visits by columnOf(1, 3, 2, 3, 2, 3, 1, 1, 2, 1)\n", - "val priority by columnOf(\"yes\", \"yes\", \"no\", \"yes\", \"no\", \"no\", \"no\", \"yes\", \"no\", \"no\")\n", - "\n", - "val df = dataFrameOf(animal, age, visits, priority)\n", + "val df = dataFrameOf(\n", + " \"animal\" to columnOf(\"cat\", \"cat\", \"snake\", \"dog\", \"dog\", \"cat\", \"snake\", \"cat\", \"dog\", \"dog\"),\n", + " \"age\" to columnOf(2.5, 3.0, 0.5, Double.NaN, 5.0, 2.0, 4.5, Double.NaN, 7.0, 3.0),\n", + " \"visits\" to columnOf(1, 3, 2, 3, 2, 3, 1, 1, 2, 1),\n", + " \"priority\" to columnOf(\"yes\", \"yes\", \"no\", \"yes\", \"no\", \"no\", \"no\", \"yes\", \"no\", \"no\"),\n", + ")\n", "df" ], "outputs": [ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
animalagevisitspriority
cat2.5000001yes
cat3.0000003yes
snake0.5000002no
\n", + "
animalagevisitspriority
cat2.5000001yes
cat3.0000003yes
snake0.5000002no
\n", " \n", " \n", " " ], @@ -2128,17 +2162,22 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:07.907697Z", - "start_time": "2025-09-09T10:20:07.711736Z" + "end_time": "2025-12-18T11:19:43.547372659Z", + "start_time": "2025-12-18T11:19:43.339126731Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_20_jupyter" + ] } }, "cell_type": "code", - "source": "df[animal, age]", + "source": "df.select { animal and age }", "outputs": [ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
animalage
dogNaN
dog5.000000
dog7.000000
\n", + "
animalage
dogNaN
dog5.000000
dog7.000000
\n", " \n", " \n", " " ], @@ -3472,8 +3516,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:10.601401Z", - "start_time": "2025-09-09T10:20:10.368239Z" + "end_time": "2025-12-18T11:19:44.130666181Z", + "start_time": "2025-12-18T11:19:43.890826650Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_24_jupyter" + ] } }, "cell_type": "code", @@ -3482,7 +3531,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
animalagevisitspriority
dogNaN3yes
catNaN1yes
\n", + "
animalagevisitspriority
dogNaN3yes
catNaN1yes
\n", " \n", " \n", " " ], @@ -4820,8 +4874,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:13.067840Z", - "start_time": "2025-09-09T10:20:12.870865Z" + "end_time": "2025-12-18T11:19:44.731860002Z", + "start_time": "2025-12-18T11:19:44.516203139Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_28_jupyter" + ] } }, "cell_type": "code", @@ -4830,7 +4889,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
animalagevisitspriority
cat2.5000001yes
cat3.0000003yes
cat2.0000003no
dog3.0000001no
\n", + "
animalagevisitspriority
cat2.5000001yes
cat3.0000003yes
cat2.0000003no
dog3.0000001no
\n", " \n", " \n", " " ], @@ -6168,8 +6232,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:15.695961Z", - "start_time": "2025-09-09T10:20:15.204861Z" + "end_time": "2025-12-18T11:19:45.321374555Z", + "start_time": "2025-12-18T11:19:45.119529698Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_32_jupyter" + ] } }, "cell_type": "code", @@ -6178,7 +6247,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
animalagevisitspriority
cat2.5000001yes
cat3.0000003yes
snake0.5000002no
dogNaN3yes
dog5.0000002no
cat2.0000003no
snake4.5000001no
catNaN1yes
dog7.0000002no
dog3.0000001no
\n", + "
animalagevisitspriority
cat2.5000001yes
cat3.0000003yes
snake0.5000002no
dogNaN3yes
dog5.0000002no
cat2.0000003no
snake4.5000001no
catNaN1yes
dog7.0000002no
dog3.0000001no
\n", " \n", " \n", " " ], @@ -8219,8 +8303,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:19.769933Z", - "start_time": "2025-09-09T10:20:19.591996Z" + "end_time": "2025-12-18T11:19:46.367888372Z", + "start_time": "2025-12-18T11:19:46.058158419Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_39_jupyter" + ] } }, "cell_type": "code", @@ -8229,7 +8318,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
animalagevisitspriority
catNaN1yes
dogNaN3yes
dog7.0000002no
dog5.0000002no
snake4.5000001no
dog3.0000001no
cat3.0000003yes
cat2.5000001yes
cat2.0000003no
snake0.5000002no
\n", + "
animalagevisitspriority
catNaN1yes
dogNaN3yes
dog7.0000002no
dog5.0000002no
snake4.5000001no
dog3.0000001no
cat3.0000003yes
cat2.5000001yes
cat2.0000003no
snake0.5000002no
\n", " \n", " \n", " " ], @@ -9565,8 +9659,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:22.589698Z", - "start_time": "2025-09-09T10:20:22.375775Z" + "end_time": "2025-12-18T11:19:46.937073806Z", + "start_time": "2025-12-18T11:19:46.722579483Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_43_jupyter" + ] } }, "cell_type": "code", @@ -9575,7 +9674,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
animalagevisitspriority
cat2.5000001yes
cat3.0000003yes
snake0.5000002no
corgiNaN3yes
corgi5.0000002no
cat2.0000003no
snake4.5000001no
catNaN1yes
corgi7.0000002no
corgi3.0000001no
\n", + "
animalagevisitspriority
cat2.5000001yes
cat3.0000003yes
snake0.5000002no
corgiNaN3yes
corgi5.0000002no
cat2.0000003no
snake4.5000001no
catNaN1yes
corgi7.0000002no
corgi3.0000001no
\n", " \n", " \n", " " ], @@ -10917,8 +11021,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:24.572846Z", - "start_time": "2025-09-09T10:20:24.294243Z" + "end_time": "2025-12-18T11:19:47.538227593Z", + "start_time": "2025-12-18T11:19:47.243994037Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_47_jupyter" + ] } }, "cell_type": "code", @@ -10927,7 +11036,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
A
1
2
2
3
4
5
5
5
6
7
7
\n", + "
A
1
2
2
3
4
5
5
5
6
7
7
\n", " \n", " \n", " " ], @@ -12284,8 +12400,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:26.967333Z", - "start_time": "2025-09-09T10:20:26.811413Z" + "end_time": "2025-12-18T11:19:48.106029432Z", + "start_time": "2025-12-18T11:19:47.883015099Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_53_jupyter" + ] } }, "cell_type": "code", @@ -12294,7 +12415,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
A
1
2
3
4
5
6
7
\n", + "
A
1
2
3
4
5
6
7
\n", " \n", " \n", " " ], @@ -13621,8 +13747,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:29.315966Z", - "start_time": "2025-09-09T10:20:29.209502Z" + "end_time": "2025-12-18T11:19:48.524516883Z", + "start_time": "2025-12-18T11:19:48.428439626Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_57_jupyter" + ] } }, "cell_type": "code", @@ -13631,7 +13762,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
abcdefghij
0.2009070.8871910.2549470.3881570.9087650.3296940.9522780.2858200.0136360.095965
0.7569150.0644090.7341920.1102490.5909990.7049050.9120190.6520980.0368660.420558
0.7711180.9882530.5219260.7316640.0221420.6355320.7668380.8530870.9068440.446849
0.2618270.7294400.2094040.6021790.8475070.7304870.1263330.5451070.7954820.378680
0.7529580.3208140.7202080.7671470.5972440.0576180.1913100.2033210.9037600.523245
\n", + "
abcdefghij
0.8419110.2821870.5048440.3160490.4903500.5932060.5507190.8143400.0890810.113149
0.4982080.8476610.2279870.5182300.1260700.6163240.1471160.2624630.3235520.737167
0.7889160.1624580.1833110.9265850.4297270.7407670.9306180.9710540.8023080.230486
0.5533470.4825940.4054610.3698490.4315320.1778260.4652870.2624960.2016740.430214
0.8749320.1620430.4775250.8840590.2925860.8548660.4564860.5893030.1404260.911116
\n", " \n", " \n", " " ], - "application/kotlindataframe+json": "{\"$version\":\"2.2.0\",\"metadata\":{\"columns\":[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"}],\"nrow\":5,\"ncol\":10,\"is_formatted\":false},\"kotlin_dataframe\":[{\"a\":0.20090685064331937,\"b\":0.8871912255133791,\"c\":0.2549468111321541,\"d\":0.38815694631380127,\"e\":0.9087653789721286,\"f\":0.3296938927440395,\"g\":0.9522777703806122,\"h\":0.2858200144042208,\"i\":0.013636055573945094,\"j\":0.09596530470652986},{\"a\":0.7569150749029241,\"b\":0.06440905190823076,\"c\":0.7341915384170767,\"d\":0.11024863730405987,\"e\":0.590999032572314,\"f\":0.7049045211724224,\"g\":0.9120191694445311,\"h\":0.6520979901678069,\"i\":0.036866394726266294,\"j\":0.42055787198537553},{\"a\":0.7711179884037822,\"b\":0.9882529014691451,\"c\":0.5219260940599081,\"d\":0.7316640236098008,\"e\":0.02214156003644352,\"f\":0.6355322467903455,\"g\":0.7668379494838335,\"h\":0.8530872406235399,\"i\":0.9068442102269314,\"j\":0.44684852264187824},{\"a\":0.26182665083165513,\"b\":0.7294403477511925,\"c\":0.2094035232312974,\"d\":0.6021794872113193,\"e\":0.8475066241565566,\"f\":0.7304873105946014,\"g\":0.12633259066356395,\"h\":0.5451066654099072,\"i\":0.7954819015909015,\"j\":0.378679721185631},{\"a\":0.7529584519095024,\"b\":0.3208139103643325,\"c\":0.7202083013432629,\"d\":0.767147363074108,\"e\":0.5972443068782157,\"f\":0.05761833328160326,\"g\":0.19130970715775053,\"h\":0.20332141649523094,\"i\":0.9037601846779532,\"j\":0.5232454636011823}]}" + "application/kotlindataframe+json": "{\"$version\":\"2.2.0\",\"metadata\":{\"columns\":[\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"}],\"nrow\":5,\"ncol\":10,\"is_formatted\":false},\"kotlin_dataframe\":[{\"a\":0.8419114160124052,\"b\":0.282186920782716,\"c\":0.5048443177170018,\"d\":0.31604901017535125,\"e\":0.4903503697680932,\"f\":0.5932062822034694,\"g\":0.5507189032521874,\"h\":0.8143400642944842,\"i\":0.0890806635407565,\"j\":0.11314865188165824},{\"a\":0.49820844533063235,\"b\":0.8476612083057321,\"c\":0.22798742360150803,\"d\":0.5182296202669303,\"e\":0.12607036482076805,\"f\":0.6163241622452882,\"g\":0.1471161686192296,\"h\":0.26246326600812764,\"i\":0.32355220762629744,\"j\":0.7371668074893234},{\"a\":0.788915937670967,\"b\":0.16245843051774012,\"c\":0.18331082327972492,\"d\":0.9265848824100162,\"e\":0.4297273634305062,\"f\":0.7407665914938036,\"g\":0.9306177608421328,\"h\":0.9710544319125589,\"i\":0.802308385674185,\"j\":0.23048565019517087},{\"a\":0.553347476141766,\"b\":0.48259411048976075,\"c\":0.40546089768988547,\"d\":0.3698490765337128,\"e\":0.43153183270372275,\"f\":0.17782580998707898,\"g\":0.465287247289943,\"h\":0.2624963066894521,\"i\":0.20167375143620148,\"j\":0.43021369129837617},{\"a\":0.8749319981380302,\"b\":0.16204312466903636,\"c\":0.4775248119116894,\"d\":0.8840586021809772,\"e\":0.2925857979551013,\"f\":0.8548662347706445,\"g\":0.4564858905910003,\"h\":0.5893027524048042,\"i\":0.1404261330157901,\"j\":0.911116058678073}]}" }, "execution_count": 27, "metadata": {}, @@ -16333,8 +16483,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:34.365240Z", - "start_time": "2025-09-09T10:20:34.058803Z" + "end_time": "2025-12-18T11:19:50.235988942Z", + "start_time": "2025-12-18T11:19:49.987687771Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_69_jupyter" + ] } }, "cell_type": "code", @@ -16343,7 +16498,7 @@ { "data": { "text/plain": [ - "j" + "i" ] }, "execution_count": 28, @@ -16361,8 +16516,15 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:35.327978Z", - "start_time": "2025-09-09T10:20:34.825964Z" + "end_time": "2025-12-18T11:19:50.387907271Z", + "start_time": "2025-12-18T11:19:50.238960093Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_70_jupyter", + "Line_71_jupyter", + "Line_72_jupyter" + ] } }, "cell_type": "code", @@ -16374,7 +16536,7 @@ { "data": { "text/plain": [ - "18" + "19" ] }, "execution_count": 29, @@ -16398,8 +16560,15 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:36.465361Z", - "start_time": "2025-09-09T10:20:35.654021Z" + "end_time": "2025-12-18T11:19:50.641509850Z", + "start_time": "2025-12-18T11:19:50.391210050Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_73_jupyter", + "Line_74_jupyter", + "Line_75_jupyter" + ] } }, "cell_type": "code", @@ -16420,7 +16589,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
res
e
c
d
h
d
\n", + "
res
e
c
d
h
d
\n", " \n", " \n", " " ], @@ -17760,10 +17934,10 @@ "source": [ "**25.** A DataFrame has a column of groups 'grps' and a column of integer values 'vals':\n", "```kotlin\n", - "val grps by column(\"a\", \"a\", \"a\", \"b\", \"b\", \"c\", \"a\", \"a\", \"b\", \"c\", \"c\", \"c\", \"b\", \"b\", \"c\")\n", - "val vals by column(12, 345, 3, 1, 45, 14, 4, 52, 54, 23, 235, 21, 57, 3, 87)\n", - "\n", - "val df = dataFrameOf(grps, vals)\n", + "val df = dataFrameOf(\n", + " \"grps\" to columnOf(\"a\", \"a\", \"a\", \"b\", \"b\", \"c\", \"a\", \"a\", \"b\", \"c\", \"c\", \"c\", \"b\", \"b\", \"c\"),\n", + " \"vals\" to columnOf(12, 345, 3, 1, 45, 14, 4, 52, 54, 23, 235, 21, 57, 3, 87),\n", + ")\n", "```\n", "\n", "For each group, find the sum of the three greatest values. You should end up with the answer as follows:\n", @@ -17778,23 +17952,30 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:39.631818Z", - "start_time": "2025-09-09T10:20:38.996891Z" + "end_time": "2025-12-18T11:19:51.467157852Z", + "start_time": "2025-12-18T11:19:51.142193506Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_79_jupyter", + "Line_80_jupyter", + "Line_81_jupyter" + ] } }, "cell_type": "code", "source": [ - "val grps by columnOf(\"a\", \"a\", \"a\", \"b\", \"b\", \"c\", \"a\", \"a\", \"b\", \"c\", \"c\", \"c\", \"b\", \"b\", \"c\")\n", - "val vals by columnOf(12, 345, 3, 1, 45, 14, 4, 52, 54, 23, 235, 21, 57, 3, 87)\n", - "\n", - "val df = dataFrameOf(grps, vals)\n", + "val df = dataFrameOf(\n", + " \"grps\" to columnOf(\"a\", \"a\", \"a\", \"b\", \"b\", \"c\", \"a\", \"a\", \"b\", \"c\", \"c\", \"c\", \"b\", \"b\", \"c\"),\n", + " \"vals\" to columnOf(12, 345, 3, 1, 45, 14, 4, 52, 54, 23, 235, 21, 57, 3, 87),\n", + ")\n", "df" ], "outputs": [ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
grpsvals
a12
a345
a3
b1
b45
c14
a4
a52
b54
c23
c235
c21
b57
b3
c87
\n", + "
grpsvals
a12
a345
a3
b1
b45
c14
a4
a52
b54
c23
c235
c21
b57
b3
c87
\n", " \n", " \n", " " ], @@ -18451,8 +18632,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:40.958555Z", - "start_time": "2025-09-09T10:20:40.712890Z" + "end_time": "2025-12-18T11:19:51.874156449Z", + "start_time": "2025-12-18T11:19:51.536795229Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_83_jupyter" + ] } }, "cell_type": "code", @@ -18465,7 +18651,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
AB
3441
423
4233
2241
7088
5368
804
5959
451
2714
708
1152
5160
4643
1717
1742
5629
5849
487
7352
\n", + "
AB
3441
423
4233
2241
7088
5368
804
5959
451
2714
708
1152
5160
4643
1717
1742
5629
5849
487
7352
\n", " \n", " \n", " " ], @@ -19821,8 +20014,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:43.816621Z", - "start_time": "2025-09-09T10:20:43.416356Z" + "end_time": "2025-12-18T11:19:52.799510118Z", + "start_time": "2025-12-18T11:19:52.372865385Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_89_jupyter" + ] } }, "cell_type": "code", @@ -19835,7 +20033,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
X
7
2
0
3
4
2
5
0
3
4
\n", + "
X
7
2
0
3
4
2
5
0
3
4
\n", " \n", " \n", " " ], @@ -21189,8 +21394,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:46.239893Z", - "start_time": "2025-09-09T10:20:46.023751Z" + "end_time": "2025-12-18T11:19:53.552737696Z", + "start_time": "2025-12-18T11:19:53.347104241Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_95_jupyter" + ] } }, "cell_type": "code", @@ -21203,7 +21413,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
Y
1
2
0
1
2
3
4
0
1
2
\n", + "
Y
1
2
0
1
2
3
4
0
1
2
\n", " \n", " \n", " " ], @@ -21873,8 +22083,15 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:47.723910Z", - "start_time": "2025-09-09T10:20:46.986249Z" + "end_time": "2025-12-18T11:19:54.071017006Z", + "start_time": "2025-12-18T11:19:53.641692715Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_97_jupyter", + "Line_98_jupyter", + "Line_99_jupyter" + ] } }, "cell_type": "code", @@ -21889,7 +22106,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
abcdefgh
4388661009597423
6634358485925
4959100522811981
9241135728976339
459726550351431
5574336617398038
186491398055652
197675183297132
\n", + "
abcdefgh
4388661009597423
6634358485925
4959100522811981
9241135728976339
459726550351431
5574336617398038
186491398055652
197675183297132
\n", " \n", " \n", " " ], @@ -22552,8 +22769,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:49.199193Z", - "start_time": "2025-09-09T10:20:48.654185Z" + "end_time": "2025-12-18T11:19:54.475257403Z", + "start_time": "2025-12-18T11:19:54.139804923Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_101_jupyter" + ] } }, "cell_type": "code", @@ -22566,7 +22788,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
valsgrps
-17B
-7B
16A
28B
9A
16B
-21B
-14A
-19A
-22A
19B
-2B
-1A
-19B
23A
\n", + "
valsgrps
-17B
-7B
16A
28B
9A
16B
-21B
-14A
-19A
-22A
19B
-2B
-1A
-19B
23A
\n", " \n", " \n", " " ], @@ -23937,8 +24166,15 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:52.921344Z", - "start_time": "2025-09-09T10:20:51.977826Z" + "end_time": "2025-12-18T11:19:55.629440336Z", + "start_time": "2025-12-18T11:19:55.172126724Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_107_jupyter", + "Line_108_jupyter", + "Line_109_jupyter" + ] } }, "cell_type": "code", @@ -23955,7 +24191,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
valsgrpspatched_values
-17B21.000000
-7B21.000000
16A16.000000
28B28.000000
9A9.000000
16B16.000000
-21B21.000000
-14A16.000000
-19A16.000000
-22A16.000000
19B19.000000
-2B21.000000
-1A16.000000
-19B21.000000
23A23.000000
\n", + "
valsgrpspatched_values
-17B21.000000
-7B21.000000
16A16.000000
28B28.000000
9A9.000000
16B16.000000
-21B21.000000
-14A16.000000
-19A16.000000
-22A16.000000
19B19.000000
-2B21.000000
-1A16.000000
-19B21.000000
23A23.000000
\n", " \n", " \n", " " ], @@ -24616,10 +24852,10 @@ "source": [ "**30.** Implement a rolling mean over groups with window size 3, which ignores NaN value. For example, consider the following DataFrame:\n", "```kotlin\n", - "val group by columnOf(\"a\", \"a\", \"b\", \"b\", \"a\", \"b\", \"b\", \"b\", \"a\", \"b\", \"a\", \"b\")\n", - "val value by columnOf(1.0, 2.0, 3.0, Double.NaN, 2.0, 3.0, Double.NaN, 1.0, 7.0, 3.0, Double.NaN, 8.0)\n", - "\n", - "val df = dataFrameOf(group, value)\n", + "val df = dataFrameOf(\n", + " \"groups\" to columnOf(\"a\", \"a\", \"b\", \"b\", \"a\", \"b\", \"b\", \"b\", \"a\", \"b\", \"a\", \"b\"),\n", + " \"value\" to columnOf(1.0, 2.0, 3.0, Double.NaN, 2.0, 3.0, Double.NaN, 1.0, 7.0, 3.0, Double.NaN, 8.0),\n", + ")\n", "df\n", "\n", "group value\n", @@ -24658,23 +24894,30 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:55.956419Z", - "start_time": "2025-09-09T10:20:54.685746Z" + "end_time": "2025-12-18T11:19:56.047538523Z", + "start_time": "2025-12-18T11:19:55.719618410Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_111_jupyter", + "Line_112_jupyter", + "Line_113_jupyter" + ] } }, "cell_type": "code", "source": [ - "val groups by columnOf(\"a\", \"a\", \"b\", \"b\", \"a\", \"b\", \"b\", \"b\", \"a\", \"b\", \"a\", \"b\")\n", - "val value by columnOf(1.0, 2.0, 3.0, Double.NaN, 2.0, 3.0, Double.NaN, 1.0, 7.0, 3.0, Double.NaN, 8.0)\n", - "\n", - "val df = dataFrameOf(groups, value)\n", + "val df = dataFrameOf(\n", + " \"groups\" to columnOf(\"a\", \"a\", \"b\", \"b\", \"a\", \"b\", \"b\", \"b\", \"a\", \"b\", \"a\", \"b\"),\n", + " \"value\" to columnOf(1.0, 2.0, 3.0, Double.NaN, 2.0, 3.0, Double.NaN, 1.0, 7.0, 3.0, Double.NaN, 8.0),\n", + ")\n", "df" ], "outputs": [ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
groupsvalueres
a1.0000001.000000
a2.0000001.500000
b3.0000003.000000
bNaN3.000000
a2.0000001.666667
b3.0000003.000000
bNaN3.000000
b1.0000002.000000
a7.0000003.666667
b3.0000002.000000
aNaN4.500000
b8.0000004.000000
\n", + "
groupsvalueres
a1.0000001.000000
a2.0000001.500000
b3.0000003.000000
bNaN3.000000
a2.0000001.666667
b3.0000003.000000
bNaN3.000000
b1.0000002.000000
a7.0000003.666667
b3.0000002.000000
aNaN4.500000
b8.0000004.000000
\n", " \n", " \n", " " ], @@ -26019,8 +26267,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:20:58.558932Z", - "start_time": "2025-09-09T10:20:58.505722Z" + "end_time": "2025-12-18T11:19:56.754450953Z", + "start_time": "2025-12-18T11:19:56.683121372Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_117_jupyter" + ] } }, "cell_type": "code", @@ -26031,8 +26284,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:21:00.685365Z", - "start_time": "2025-09-09T10:20:59.536462Z" + "end_time": "2025-12-18T11:19:57.126047058Z", + "start_time": "2025-12-18T11:19:56.791536294Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_118_jupyter" + ] } }, "cell_type": "code", @@ -26078,8 +26336,15 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:21:02.442214Z", - "start_time": "2025-09-09T10:21:01.069826Z" + "end_time": "2025-12-18T11:19:57.565043672Z", + "start_time": "2025-12-18T11:19:57.140265113Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_119_jupyter", + "Line_120_jupyter", + "Line_121_jupyter" + ] } }, "cell_type": "code", @@ -26089,16 +26354,17 @@ "\n", "val days = (start..end).toList()\n", "\n", - "val dti = days.toColumn(\"dti\")\n", - "val s = List(dti.size()) { Random.nextDouble() }.toColumn(\"s\")\n", - "val df = dataFrameOf(dti, s)\n", + "val df = dataFrameOf(\n", + " \"dti\" to days.toColumn(),\n", + " \"s\" to List(days.size) { Random.nextDouble() }.toColumn()\n", + ")\n", "df.head()" ], "outputs": [ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
month4max
dtismonth4
12015-04-200.9961421
22015-07-220.9963762
32015-09-150.9984813
\n", + "
month4max
dtismonth4
12015-03-220.9982801
22015-05-140.9914552
32015-12-160.9998913
\n", " \n", " \n", " " ], - "application/kotlindataframe+json": "{\"$version\":\"2.2.0\",\"metadata\":{\"columns\":[\"month4\",\"max\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ColumnGroup\"}],\"nrow\":3,\"ncol\":2,\"is_formatted\":false},\"kotlin_dataframe\":[{\"month4\":1,\"max\":{\"data\":{\"dti\":\"2015-04-20\",\"s\":0.996142449438107,\"month4\":1},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"dti\",\"s\",\"month4\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlinx.datetime.LocalDate\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"month4\":2,\"max\":{\"data\":{\"dti\":\"2015-07-22\",\"s\":0.9963756973660238,\"month4\":2},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"dti\",\"s\",\"month4\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlinx.datetime.LocalDate\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"month4\":3,\"max\":{\"data\":{\"dti\":\"2015-09-15\",\"s\":0.9984806388730291,\"month4\":3},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"dti\",\"s\",\"month4\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlinx.datetime.LocalDate\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}}]}" + "application/kotlindataframe+json": "{\"$version\":\"2.2.0\",\"metadata\":{\"columns\":[\"month4\",\"max\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ColumnGroup\"}],\"nrow\":3,\"ncol\":2,\"is_formatted\":false},\"kotlin_dataframe\":[{\"month4\":1,\"max\":{\"data\":{\"dti\":\"2015-03-22\",\"s\":0.9982800125376523,\"month4\":1},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"dti\",\"s\",\"month4\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlinx.datetime.LocalDate\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"month4\":2,\"max\":{\"data\":{\"dti\":\"2015-05-14\",\"s\":0.9914549696180743,\"month4\":2},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"dti\",\"s\",\"month4\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlinx.datetime.LocalDate\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"month4\":3,\"max\":{\"data\":{\"dti\":\"2015-12-16\",\"s\":0.9998914835120076,\"month4\":3},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"dti\",\"s\",\"month4\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlinx.datetime.LocalDate\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Double\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}}]}" }, "execution_count": 49, "metadata": {}, @@ -28143,8 +28424,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:21:06.740021Z", - "start_time": "2025-09-09T10:21:06.693834Z" + "end_time": "2025-12-18T11:19:58.720573737Z", + "start_time": "2025-12-18T11:19:58.641394272Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_128_jupyter" + ] } }, "cell_type": "code", @@ -28158,8 +28444,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:21:08.229904Z", - "start_time": "2025-09-09T10:21:07.618142Z" + "end_time": "2025-12-18T11:19:59.016056372Z", + "start_time": "2025-12-18T11:19:58.722834006Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_129_jupyter" + ] } }, "cell_type": "code", @@ -28176,7 +28467,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
From_ToFlightNumberRecentDelaysAirline
LoNDon_paris10045.000000[23, 47]KLM(!)
MAdrid_miLANNaN[ ]{Air France} (12)
londON_StockhOlm10065.000000[24, 43, 87](British Airways. )
Budapest_PaRisNaN[13]12. Air France
Brussels_londOn10085.000000[67, 32]'Swiss Air'
\n", + "
From_ToFlightNumberRecentDelaysAirline
LoNDon_paris10045.000000[23, 47]KLM(!)
MAdrid_miLANNaN[ ]{Air France} (12)
londON_StockhOlm10065.000000[24, 43, 87](British Airways. )
Budapest_PaRisNaN[13]12. Air France
Brussels_londOn10085.000000[67, 32]'Swiss Air'
\n", " \n", " \n", " " ], @@ -29549,8 +29847,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:21:11.999406Z", - "start_time": "2025-09-09T10:21:11.582393Z" + "end_time": "2025-12-18T11:20:00.173798942Z", + "start_time": "2025-12-18T11:19:59.836065273Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_135_jupyter" + ] } }, "cell_type": "code", @@ -29564,7 +29867,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
FromToFlightNumberRecentDelaysAirline
LoNDonparis10045[23, 47]KLM(!)
MAdridmiLAN10055[ ]{Air France} (12)
londONStockhOlm10065[24, 43, 87](British Airways. )
BudapestPaRis10075[13]12. Air France
BrusselslondOn10085[67, 32]'Swiss Air'
\n", + "
FromToFlightNumberRecentDelaysAirline
LoNDonparis10045[23, 47]KLM(!)
MAdridmiLAN10055[ ]{Air France} (12)
londONStockhOlm10065[24, 43, 87](British Airways. )
BudapestPaRis10075[13]12. Air France
BrusselslondOn10085[67, 32]'Swiss Air'
\n", " \n", " \n", " " ], @@ -30914,8 +31224,13 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:21:14.533957Z", - "start_time": "2025-09-09T10:21:14.142724Z" + "end_time": "2025-12-18T11:20:00.993293322Z", + "start_time": "2025-12-18T11:20:00.698864044Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_141_jupyter" + ] } }, "cell_type": "code", @@ -30927,7 +31242,7 @@ { "data": { "text/html": [ - " \n", " \n", + " \n", " \n", " \n", " \n", " \n", - "
FromToFlightNumberRecentDelaysAirline
LondonParis10045[23, 47]KLM
MadridMilan10055[ ]Air France
LondonStockholm10065[24, 43, 87]British Airways
BudapestParis10075[13] Air France
BrusselsLondon10085[67, 32]Swiss Air
\n", + "
FromToFlightNumberRecentDelaysAirline
LondonParis10045[23, 47]KLM
MadridMilan10055[ ]Air France
LondonStockholm10065[24, 43, 87]British Airways
BudapestParis10075[13] Air France
BrusselsLondon10085[67, 32]Swiss Air
\n", " \n", " \n", " " ], @@ -32281,20 +32601,27 @@ { "metadata": { "ExecuteTime": { - "end_time": "2025-09-09T10:21:17.414060Z", - "start_time": "2025-09-09T10:21:16.638036Z" + "end_time": "2025-12-18T11:20:01.740439057Z", + "start_time": "2025-12-18T11:20:01.448232137Z" + }, + "executionRelatedData": { + "compiledClasses": [ + "Line_145_jupyter", + "Line_146_jupyter", + "Line_147_jupyter" + ] } }, "cell_type": "code", "source": [ - "val prep_df = df2.split { RecentDelays }.into { \"delay_$it\" }\n", - "prep_df" + "val cleanDf = df2.split { RecentDelays }.into { \"delay_$it\" }\n", + "cleanDf" ], "outputs": [ { "data": { "text/html": [ - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
fromtoflightNumberdelay1delay2delay3airline
LondonParis100452347nullKLM
MadridMilan10055nullnullnullAir France
LondonStockholm10065244387British Airways
BudapestParis1007513nullnull Air France
BrusselsLondon100856732nullSwiss Air
\n", + " \n", + " \n", + " " + ], + "application/kotlindataframe+json": "{\"$version\":\"2.2.0\",\"metadata\":{\"columns\":[\"from\",\"to\",\"flightNumber\",\"delay1\",\"delay2\",\"delay3\",\"airline\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int?\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int?\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int?\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"}],\"nrow\":5,\"ncol\":7,\"is_formatted\":false},\"kotlin_dataframe\":[{\"from\":\"London\",\"to\":\"Paris\",\"flightNumber\":10045,\"delay1\":23,\"delay2\":47,\"delay3\":null,\"airline\":\"KLM\"},{\"from\":\"Madrid\",\"to\":\"Milan\",\"flightNumber\":10055,\"delay1\":null,\"delay2\":null,\"delay3\":null,\"airline\":\"Air France\"},{\"from\":\"London\",\"to\":\"Stockholm\",\"flightNumber\":10065,\"delay1\":24,\"delay2\":43,\"delay3\":87,\"airline\":\"British Airways\"},{\"from\":\"Budapest\",\"to\":\"Paris\",\"flightNumber\":10075,\"delay1\":13,\"delay2\":null,\"delay3\":null,\"airline\":\" Air France\"},{\"from\":\"Brussels\",\"to\":\"London\",\"flightNumber\":10085,\"delay1\":67,\"delay2\":32,\"delay3\":null,\"airline\":\"Swiss Air\"}]}" + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "execution_count": 58 } ], "metadata": {