{
"cells": [
{
"cell_type": "markdown",
"id": "90cc0c45",
"metadata": {},
"source": [
"# Kotlin DataFrame: Getting Started\n",
"\n",
"## What is this\n",
"\n",
"This is a short introduction for those Kotlin developers, who are familiar at least with the syntax and basic concepts of Kotlin\n",
"\n",
"## What is this **not**\n",
"\n",
"This is not a guide that will help you to migrate from another language or technology to Kotlin DataFrame\n",
"\n",
"## What is Kotlin DataFrame\n",
"\n",
"_From now on I will refer to this library as \"KotlinDF\". Although it is not the official name, it's much shorter and comfortable to use._\n",
"\n",
"KotlinDF is a library to work with DataFrames. DataFrame is a simple representation of any table-like data that has columns and rows.\n",
"Anyone who has seen products like MS Excel is already familiar with DF: one can add/remove/operate on columns/rows/cells, name, etc.\n",
"\n",
"But of course programming gives us very powerful tools which are hard to use in spreadsheet editors — aggregations for example.\n",
"\n",
"## Getting started\n",
"\n",
"### Task\n",
"\n",
"https://movielens.org/ is an online service, providing recommendations based on user's taste.\n",
"Users may grade any movie from on a scale from 1 to 10, and some algorithm will give them recommendations based on their taste and the taste of other users.\n",
"\n",
"Indeed, this service should contain comprehensive information about movies and, of course, lots of information produced by users, like tags.\n",
"\n",
"You can collect data [here](https://grouplens.org/datasets/movielens/). We will use some example data.\n",
"\n",
"Today we're going to find the following information:\n",
"\n",
"1. Find the most popular genre of movies since 1920\n",
"2. Find the most tagged movie\n",
"\n",
"### Find the most popular genre of movies since 1920\n",
"\n",
"To query data, we should at first read it. Read it to a DF in our case. This is how we do that:"
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:20:51.491311Z",
"start_time": "2025-05-27T14:20:46.082916Z"
}
},
"cell_type": "code",
"source": [
"%useLatestDescriptors\n",
"%use dataframe"
],
"id": "74cf06e74a2d456a",
"outputs": [],
"execution_count": 1
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:20:54.559862Z",
"start_time": "2025-05-27T14:20:51.507819Z"
}
},
"cell_type": "code",
"source": "val rawMovies = DataFrame.read(\"movies.csv\")",
"id": "270f3eea1123fadf",
"outputs": [],
"execution_count": 2
},
{
"cell_type": "markdown",
"id": "51368a9d",
"metadata": {},
"source": [
"Yes, it's that simple!\n",
"KotlinDF determines a format itself and loads the data into a value, called `rawMovies`\n",
"\n",
"But how should we query this data? We don't even know what it looks like.\n",
"Let's explore it.\n",
"\n",
"This very basic statement will do the magic and will output the result:\n"
]
},
{
"cell_type": "code",
"id": "ca3dda7f",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:20:55.071183Z",
"start_time": "2025-05-27T14:20:54.579220Z"
}
},
"source": [
"rawMovies.head()"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
"
\n",
" \n",
" \n",
" \n",
" | movieId | title | genres |
|---|
| 9b30aff7943f44579e92c261f3adc193 | Women in Black (1997) | Fantasy|Suspenseful|Comedy |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie (2007) | Comedy|Jazz|Family|Animation |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | Fantasy|Growing up|Magic |
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | Fantasy|Magic|Suspenseful |
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espai... | Fantasy |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"movieId\",\"title\",\"genres\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"}],\"nrow\":5,\"ncol\":3},\"kotlin_dataframe\":[{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black (1997)\",\"genres\":\"Fantasy|Suspenseful|Comedy\"},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie (2007)\",\"genres\":\"Comedy|Jazz|Family|Animation\"},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men (2001)\",\"genres\":\"Fantasy|Growing up|Magic\"},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel (2001)\",\"genres\":\"Fantasy|Magic|Suspenseful\"},{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair (1977)\",\"genres\":\"Fantasy\"}]}"
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 3
},
{
"cell_type": "markdown",
"id": "0d1b25d6",
"metadata": {},
"source": [
"The structure is simple, right? Just three columns:\n",
"\n",
"1. movieId\n",
"2. title\n",
"3. genres\n",
"\n",
"_NB: Interesting observation: without any effort from our side, KotlinDF already determined the type of each column._\n",
"\n",
"And furthermore, we can already see how to solve our first task.\n",
"\n",
"What do we need to do?\n",
"\n",
"1. Extract the year to a separate column\n",
"2. If the year is not known — remove the movie from our DF — it's not relevant for us\n",
"3. Remove the year from the title (because it's not an actual part of the title)\n",
"4. If genre is `(no genres listed)` — remove the movie from our DF — it's irrelevant for us\n",
"5. Split genres by `|` simple\n",
"6. Convert each row with multiple genres into multiple rows with a single genre each\n",
"7. Group the data by year and genre\n",
"8. Count the number of movies in each year-genre bucket\n",
"\n",
"#### Extract the year to a separate column\n",
"\n",
"To add a column based on another column, we can use the `add` function. In our case it will look like this:"
]
},
{
"cell_type": "code",
"id": "c6e55d9e",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:20:56.077515Z",
"start_time": "2025-05-27T14:20:55.078446Z"
}
},
"source": [
"val moviesWithYear = rawMovies\n",
" .add(\"year\"/* ① */) {\n",
" \"\\\\d{4}\".toRegex() /* ② */\n",
" .findAll(title/* ③ */)\n",
" .lastOrNull()/* ④ */\n",
" ?.value\n",
" ?.toInt()/* ⑤ */\n",
" ?: -1 /* ⑥ */\n",
" }"
],
"outputs": [],
"execution_count": 4
},
{
"cell_type": "markdown",
"id": "fbbb48d2",
"metadata": {},
"source": [
"Let's look at all interesting places in this expression.\n",
"\n",
"- ① - We're adding a column named `year`\n",
"- ② - To add a column, we'll use the regular expression `\\\\d{4}`; this just looks for any consecutive four digits\n",
"- ③ - thanks to jupyter's magic, we can call the column just by name! In other environments the syntax may be a bit more cluttered, for example `\"title\"()`. _However, when the [compiler plugin is enabled](https://kotlin.github.io/dataframe/compiler-plugin.html), the same notation works in any project!_\n",
"- ④ - We are looking for the latest possible appearance of 4-digit sequences, or, if there are no such sequences we return `null`.\n",
"- ⑤ - If it exists we're casting it to `Int`\n",
"- ⑥ - Otherwise we're returning `-1`. We have a strong belief that there are no movies filmed before 0 AD...\n",
" \n",
"Let's check if we've achieved our first goal, by calling `head` again. The output is:\n"
]
},
{
"cell_type": "code",
"id": "6bcdbe7e",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:20:56.296976Z",
"start_time": "2025-05-27T14:20:56.096706Z"
}
},
"source": [
"moviesWithYear.head()"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | movieId | title | genres | year |
|---|
| 9b30aff7943f44579e92c261f3adc193 | Women in Black (1997) | Fantasy|Suspenseful|Comedy | 1997 |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie (2007) | Comedy|Jazz|Family|Animation | 2007 |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | Fantasy|Growing up|Magic | 2001 |
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | Fantasy|Magic|Suspenseful | 2001 |
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espai... | Fantasy | 1977 |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"nrow\":5,\"ncol\":4},\"kotlin_dataframe\":[{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black (1997)\",\"genres\":\"Fantasy|Suspenseful|Comedy\",\"year\":1997},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie (2007)\",\"genres\":\"Comedy|Jazz|Family|Animation\",\"year\":2007},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men (2001)\",\"genres\":\"Fantasy|Growing up|Magic\",\"year\":2001},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel (2001)\",\"genres\":\"Fantasy|Magic|Suspenseful\",\"year\":2001},{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair (1977)\",\"genres\":\"Fantasy\",\"year\":1977}]}"
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 5
},
{
"cell_type": "markdown",
"id": "2f03354c",
"metadata": {},
"source": [
"Looks fine!\n",
"\n",
"#### Now let's remove year from the title\n",
"\n",
"For this we will use the `update` function. The regex here might look complex, so here is a small explanation of it:\n",
"\n",
"```java\n",
"\"\\\\s\" + // Match a single character that is a “whitespace character”\n",
" \"*\" + // Between zero and unlimited times, as many times as possible, giving back as needed\n",
"\"\\\\\\(\" + // Match the opening parenthesis character\n",
"\"\\\\d\" + // Match a single character that is a “digit”\n",
" \"{4}\" + // Exactly 4 times\n",
"\"\\\\\\)\" + // Match the closing parenthesis character\n",
"\"\\\\s\" + // Match a single character that is a “whitespace character”\n",
" \"*\" + // Between zero and unlimited times, as many times as possible, giving back as needed\n",
"\"$\" // Assert position at the end of the string, or before the line break at the end of the string, if any\n",
"```"
]
},
{
"cell_type": "code",
"id": "e9d93026",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:20:56.585030Z",
"start_time": "2025-05-27T14:20:56.306499Z"
}
},
"source": [
"val movies = moviesWithYear\n",
" .update(\"title\") {\n",
" \"\\\\s*\\\\(\\\\d{4}\\\\)\\\\s*$\".toRegex().replace(title, \"\")\n",
" }"
],
"outputs": [],
"execution_count": 6
},
{
"cell_type": "markdown",
"id": "6caf6df7",
"metadata": {},
"source": [
"#### Remove movies older than 1920\n",
"\n",
"Filtering is quite easy, we need to just call the `filter function`, like this:\n"
]
},
{
"cell_type": "code",
"id": "b1c3ea1b",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:20:56.891455Z",
"start_time": "2025-05-27T14:20:56.590909Z"
}
},
"source": [
"movies.filter { year >= 1920 }"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | movieId | title | genres | year |
|---|
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | Fantasy|Suspenseful|Comedy | 1997 |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | Comedy|Jazz|Family|Animation | 2007 |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | Fantasy|Growing up|Magic | 2001 |
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | Fantasy|Magic|Suspenseful | 2001 |
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espair | Fantasy | 1977 |
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | Fantasy|Superhero|Family | 2008 |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | Horror|Existential | 2014 |
| c1f0a868aeb44c5ea8d154ec3ca295ac | Interplanetary | Sci-fi|Futuristic | 2014 |
| 9595b771f87f42a3b8dd07d91e7cb328 | Woods Run | Family|Drama | 1994 |
| aa9fc400e068443488b259ea0802a975 | Anthropod-Dude | Superhero|Fantasy|Family|Growing up | 2002 |
| 22d20c2ba11d44cab83aceea39dc00bd | The Chamber | Comedy|Drama | 2003 |
| 8cf4d0c1bd7b41fab6af9d92c892141f | That Thing About an Iceberg | Drama|History|Family|Romance | 1997 |
| c2f3e7588da84684a7d78d6bd8d8e1f4 | Vehicles | Animation|Family | 2006 |
| ce06175106af4105945f245161eac3c7 | Playthings Tale | Animation|Family | 1995 |
| ee28d7e69103485c83e10b8055ef15fb | Metal Man 2 | Fantasy|Superhero|Family | 2010 |
| c32bdeed466f4ec09de828bb4b6fc649 | Surgeon Odd in the Omniverse of Crazy | Fantasy|Superhero|Family|Horror | 2022 |
| d4a325ab648a42c4a2d6f35dfabb387f | Bad Dream on Pine Street | Horror | 1984 |
| 60ebe74947234ddcab49dea1a958faed | The Shimmering | Horror | 1980 |
| f24327f2b05147b197ca34bf13ae3524 | Krubit: Societal Teachings for Do Man... | Comedy | 2006 |
| 2bb29b3a245e434fa80542e711fd2cee | This is No Movie | (no genres listed) | 1950 |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"nrow\":20,\"ncol\":4},\"kotlin_dataframe\":[{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"genres\":\"Fantasy|Suspenseful|Comedy\",\"year\":1997},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":\"Comedy|Jazz|Family|Animation\",\"year\":2007},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"genres\":\"Fantasy|Growing up|Magic\",\"year\":2001},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"genres\":\"Fantasy|Magic|Suspenseful\",\"year\":2001},{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair\",\"genres\":\"Fantasy\",\"year\":1977},{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"genres\":\"Fantasy|Superhero|Family\",\"year\":2008},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":\"Horror|Existential\",\"year\":2014},{\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"title\":\"Interplanetary\",\"genres\":\"Sci-fi|Futuristic\",\"year\":2014},{\"movieId\":\"9595b771f87f42a3b8dd07d91e7cb328\",\"title\":\"Woods Run\",\"genres\":\"Family|Drama\",\"year\":1994},{\"movieId\":\"aa9fc400e068443488b259ea0802a975\",\"title\":\"Anthropod-Dude\",\"genres\":\"Superhero|Fantasy|Family|Growing up\",\"year\":2002},{\"movieId\":\"22d20c2ba11d44cab83aceea39dc00bd\",\"title\":\"The Chamber\",\"genres\":\"Comedy|Drama\",\"year\":2003},{\"movieId\":\"8cf4d0c1bd7b41fab6af9d92c892141f\",\"title\":\"That Thing About an Iceberg\",\"genres\":\"Drama|History|Family|Romance\",\"year\":1997},{\"movieId\":\"c2f3e7588da84684a7d78d6bd8d8e1f4\",\"title\":\"Vehicles\",\"genres\":\"Animation|Family\",\"year\":2006},{\"movieId\":\"ce06175106af4105945f245161eac3c7\",\"title\":\"Playthings Tale\",\"genres\":\"Animation|Family\",\"year\":1995},{\"movieId\":\"ee28d7e69103485c83e10b8055ef15fb\",\"title\":\"Metal Man 2\",\"genres\":\"Fantasy|Superhero|Family\",\"year\":2010},{\"movieId\":\"c32bdeed466f4ec09de828bb4b6fc649\",\"title\":\"Surgeon Odd in the Omniverse of Crazy\",\"genres\":\"Fantasy|Superhero|Family|Horror\",\"year\":2022},{\"movieId\":\"d4a325ab648a42c4a2d6f35dfabb387f\",\"title\":\"Bad Dream on Pine Street\",\"genres\":\"Horror\",\"year\":1984},{\"movieId\":\"60ebe74947234ddcab49dea1a958faed\",\"title\":\"The Shimmering\",\"genres\":\"Horror\",\"year\":1980},{\"movieId\":\"f24327f2b05147b197ca34bf13ae3524\",\"title\":\"Krubit: Societal Teachings for Do Many Good Amazing Country of Uzbekistan\",\"genres\":\"Comedy\",\"year\":2006},{\"movieId\":\"2bb29b3a245e434fa80542e711fd2cee\",\"title\":\"This is No Movie\",\"genres\":\"(no genres listed)\",\"year\":1950}]}"
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 7
},
{
"cell_type": "markdown",
"id": "b9396ccb",
"metadata": {},
"source": [
"#### Remove lines where genre is `(no genres listed)`\n",
"\n",
"It's quite a simple operation again, just one more filter"
]
},
{
"cell_type": "code",
"id": "b40766a9",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:20:57.192042Z",
"start_time": "2025-05-27T14:20:56.897102Z"
}
},
"source": [
"movies\n",
" .filter { year >= 1920 }\n",
" .filter { genres != \"(no genres listed)\" }"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | movieId | title | genres | year |
|---|
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | Fantasy|Suspenseful|Comedy | 1997 |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | Comedy|Jazz|Family|Animation | 2007 |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | Fantasy|Growing up|Magic | 2001 |
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | Fantasy|Magic|Suspenseful | 2001 |
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espair | Fantasy | 1977 |
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | Fantasy|Superhero|Family | 2008 |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | Horror|Existential | 2014 |
| c1f0a868aeb44c5ea8d154ec3ca295ac | Interplanetary | Sci-fi|Futuristic | 2014 |
| 9595b771f87f42a3b8dd07d91e7cb328 | Woods Run | Family|Drama | 1994 |
| aa9fc400e068443488b259ea0802a975 | Anthropod-Dude | Superhero|Fantasy|Family|Growing up | 2002 |
| 22d20c2ba11d44cab83aceea39dc00bd | The Chamber | Comedy|Drama | 2003 |
| 8cf4d0c1bd7b41fab6af9d92c892141f | That Thing About an Iceberg | Drama|History|Family|Romance | 1997 |
| c2f3e7588da84684a7d78d6bd8d8e1f4 | Vehicles | Animation|Family | 2006 |
| ce06175106af4105945f245161eac3c7 | Playthings Tale | Animation|Family | 1995 |
| ee28d7e69103485c83e10b8055ef15fb | Metal Man 2 | Fantasy|Superhero|Family | 2010 |
| c32bdeed466f4ec09de828bb4b6fc649 | Surgeon Odd in the Omniverse of Crazy | Fantasy|Superhero|Family|Horror | 2022 |
| d4a325ab648a42c4a2d6f35dfabb387f | Bad Dream on Pine Street | Horror | 1984 |
| 60ebe74947234ddcab49dea1a958faed | The Shimmering | Horror | 1980 |
| f24327f2b05147b197ca34bf13ae3524 | Krubit: Societal Teachings for Do Man... | Comedy | 2006 |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"nrow\":19,\"ncol\":4},\"kotlin_dataframe\":[{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"genres\":\"Fantasy|Suspenseful|Comedy\",\"year\":1997},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":\"Comedy|Jazz|Family|Animation\",\"year\":2007},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"genres\":\"Fantasy|Growing up|Magic\",\"year\":2001},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"genres\":\"Fantasy|Magic|Suspenseful\",\"year\":2001},{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair\",\"genres\":\"Fantasy\",\"year\":1977},{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"genres\":\"Fantasy|Superhero|Family\",\"year\":2008},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":\"Horror|Existential\",\"year\":2014},{\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"title\":\"Interplanetary\",\"genres\":\"Sci-fi|Futuristic\",\"year\":2014},{\"movieId\":\"9595b771f87f42a3b8dd07d91e7cb328\",\"title\":\"Woods Run\",\"genres\":\"Family|Drama\",\"year\":1994},{\"movieId\":\"aa9fc400e068443488b259ea0802a975\",\"title\":\"Anthropod-Dude\",\"genres\":\"Superhero|Fantasy|Family|Growing up\",\"year\":2002},{\"movieId\":\"22d20c2ba11d44cab83aceea39dc00bd\",\"title\":\"The Chamber\",\"genres\":\"Comedy|Drama\",\"year\":2003},{\"movieId\":\"8cf4d0c1bd7b41fab6af9d92c892141f\",\"title\":\"That Thing About an Iceberg\",\"genres\":\"Drama|History|Family|Romance\",\"year\":1997},{\"movieId\":\"c2f3e7588da84684a7d78d6bd8d8e1f4\",\"title\":\"Vehicles\",\"genres\":\"Animation|Family\",\"year\":2006},{\"movieId\":\"ce06175106af4105945f245161eac3c7\",\"title\":\"Playthings Tale\",\"genres\":\"Animation|Family\",\"year\":1995},{\"movieId\":\"ee28d7e69103485c83e10b8055ef15fb\",\"title\":\"Metal Man 2\",\"genres\":\"Fantasy|Superhero|Family\",\"year\":2010},{\"movieId\":\"c32bdeed466f4ec09de828bb4b6fc649\",\"title\":\"Surgeon Odd in the Omniverse of Crazy\",\"genres\":\"Fantasy|Superhero|Family|Horror\",\"year\":2022},{\"movieId\":\"d4a325ab648a42c4a2d6f35dfabb387f\",\"title\":\"Bad Dream on Pine Street\",\"genres\":\"Horror\",\"year\":1984},{\"movieId\":\"60ebe74947234ddcab49dea1a958faed\",\"title\":\"The Shimmering\",\"genres\":\"Horror\",\"year\":1980},{\"movieId\":\"f24327f2b05147b197ca34bf13ae3524\",\"title\":\"Krubit: Societal Teachings for Do Many Good Amazing Country of Uzbekistan\",\"genres\":\"Comedy\",\"year\":2006}]}"
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 8
},
{
"cell_type": "markdown",
"id": "e4f82cc7",
"metadata": {},
"source": [
"Or you can do everything in one filter"
]
},
{
"cell_type": "code",
"id": "ea387005",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:20:57.454931Z",
"start_time": "2025-05-27T14:20:57.196797Z"
}
},
"source": [
"movies.filter { year >= 1920 && genres != \"(no genres listed)\" }"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | movieId | title | genres | year |
|---|
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | Fantasy|Suspenseful|Comedy | 1997 |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | Comedy|Jazz|Family|Animation | 2007 |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | Fantasy|Growing up|Magic | 2001 |
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | Fantasy|Magic|Suspenseful | 2001 |
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espair | Fantasy | 1977 |
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | Fantasy|Superhero|Family | 2008 |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | Horror|Existential | 2014 |
| c1f0a868aeb44c5ea8d154ec3ca295ac | Interplanetary | Sci-fi|Futuristic | 2014 |
| 9595b771f87f42a3b8dd07d91e7cb328 | Woods Run | Family|Drama | 1994 |
| aa9fc400e068443488b259ea0802a975 | Anthropod-Dude | Superhero|Fantasy|Family|Growing up | 2002 |
| 22d20c2ba11d44cab83aceea39dc00bd | The Chamber | Comedy|Drama | 2003 |
| 8cf4d0c1bd7b41fab6af9d92c892141f | That Thing About an Iceberg | Drama|History|Family|Romance | 1997 |
| c2f3e7588da84684a7d78d6bd8d8e1f4 | Vehicles | Animation|Family | 2006 |
| ce06175106af4105945f245161eac3c7 | Playthings Tale | Animation|Family | 1995 |
| ee28d7e69103485c83e10b8055ef15fb | Metal Man 2 | Fantasy|Superhero|Family | 2010 |
| c32bdeed466f4ec09de828bb4b6fc649 | Surgeon Odd in the Omniverse of Crazy | Fantasy|Superhero|Family|Horror | 2022 |
| d4a325ab648a42c4a2d6f35dfabb387f | Bad Dream on Pine Street | Horror | 1984 |
| 60ebe74947234ddcab49dea1a958faed | The Shimmering | Horror | 1980 |
| f24327f2b05147b197ca34bf13ae3524 | Krubit: Societal Teachings for Do Man... | Comedy | 2006 |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"nrow\":19,\"ncol\":4},\"kotlin_dataframe\":[{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"genres\":\"Fantasy|Suspenseful|Comedy\",\"year\":1997},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":\"Comedy|Jazz|Family|Animation\",\"year\":2007},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"genres\":\"Fantasy|Growing up|Magic\",\"year\":2001},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"genres\":\"Fantasy|Magic|Suspenseful\",\"year\":2001},{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair\",\"genres\":\"Fantasy\",\"year\":1977},{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"genres\":\"Fantasy|Superhero|Family\",\"year\":2008},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":\"Horror|Existential\",\"year\":2014},{\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"title\":\"Interplanetary\",\"genres\":\"Sci-fi|Futuristic\",\"year\":2014},{\"movieId\":\"9595b771f87f42a3b8dd07d91e7cb328\",\"title\":\"Woods Run\",\"genres\":\"Family|Drama\",\"year\":1994},{\"movieId\":\"aa9fc400e068443488b259ea0802a975\",\"title\":\"Anthropod-Dude\",\"genres\":\"Superhero|Fantasy|Family|Growing up\",\"year\":2002},{\"movieId\":\"22d20c2ba11d44cab83aceea39dc00bd\",\"title\":\"The Chamber\",\"genres\":\"Comedy|Drama\",\"year\":2003},{\"movieId\":\"8cf4d0c1bd7b41fab6af9d92c892141f\",\"title\":\"That Thing About an Iceberg\",\"genres\":\"Drama|History|Family|Romance\",\"year\":1997},{\"movieId\":\"c2f3e7588da84684a7d78d6bd8d8e1f4\",\"title\":\"Vehicles\",\"genres\":\"Animation|Family\",\"year\":2006},{\"movieId\":\"ce06175106af4105945f245161eac3c7\",\"title\":\"Playthings Tale\",\"genres\":\"Animation|Family\",\"year\":1995},{\"movieId\":\"ee28d7e69103485c83e10b8055ef15fb\",\"title\":\"Metal Man 2\",\"genres\":\"Fantasy|Superhero|Family\",\"year\":2010},{\"movieId\":\"c32bdeed466f4ec09de828bb4b6fc649\",\"title\":\"Surgeon Odd in the Omniverse of Crazy\",\"genres\":\"Fantasy|Superhero|Family|Horror\",\"year\":2022},{\"movieId\":\"d4a325ab648a42c4a2d6f35dfabb387f\",\"title\":\"Bad Dream on Pine Street\",\"genres\":\"Horror\",\"year\":1984},{\"movieId\":\"60ebe74947234ddcab49dea1a958faed\",\"title\":\"The Shimmering\",\"genres\":\"Horror\",\"year\":1980},{\"movieId\":\"f24327f2b05147b197ca34bf13ae3524\",\"title\":\"Krubit: Societal Teachings for Do Many Good Amazing Country of Uzbekistan\",\"genres\":\"Comedy\",\"year\":2006}]}"
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 9
},
{
"cell_type": "markdown",
"id": "98b6251c",
"metadata": {},
"source": [
"#### Split genres by the \"`|`\" symbol\n",
"\n",
"Here we meet the next exciting concept of KotlinDF: built-in column operations.\n",
"Most of them can be called right on a dataframe!\n",
"One of them is the `split` operation."
]
},
{
"cell_type": "code",
"id": "a9010baa",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:20:57.900212Z",
"start_time": "2025-05-27T14:20:57.461309Z"
}
},
"source": [
"movies\n",
" .filter { year >= 1920 && genres != \"(no genres listed)\" }\n",
" .split { genres }.by(\"|\").inplace()"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | movieId | title | genres | year |
|---|
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | [Fantasy, Suspenseful, Comedy] | 1997 |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | [Comedy, Jazz, Family, Animation] | 2007 |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | [Fantasy, Growing up, Magic] | 2001 |
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | [Fantasy, Magic, Suspenseful] | 2001 |
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espair | [Fantasy] | 1977 |
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | [Fantasy, Superhero, Family] | 2008 |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | [Horror, Existential] | 2014 |
| c1f0a868aeb44c5ea8d154ec3ca295ac | Interplanetary | [Sci-fi, Futuristic] | 2014 |
| 9595b771f87f42a3b8dd07d91e7cb328 | Woods Run | [Family, Drama] | 1994 |
| aa9fc400e068443488b259ea0802a975 | Anthropod-Dude | [Superhero, Fantasy, Family, Growing up] | 2002 |
| 22d20c2ba11d44cab83aceea39dc00bd | The Chamber | [Comedy, Drama] | 2003 |
| 8cf4d0c1bd7b41fab6af9d92c892141f | That Thing About an Iceberg | [Drama, History, Family, Romance] | 1997 |
| c2f3e7588da84684a7d78d6bd8d8e1f4 | Vehicles | [Animation, Family] | 2006 |
| ce06175106af4105945f245161eac3c7 | Playthings Tale | [Animation, Family] | 1995 |
| ee28d7e69103485c83e10b8055ef15fb | Metal Man 2 | [Fantasy, Superhero, Family] | 2010 |
| c32bdeed466f4ec09de828bb4b6fc649 | Surgeon Odd in the Omniverse of Crazy | [Fantasy, Superhero, Family, Horror] | 2022 |
| d4a325ab648a42c4a2d6f35dfabb387f | Bad Dream on Pine Street | [Horror] | 1984 |
| 60ebe74947234ddcab49dea1a958faed | The Shimmering | [Horror] | 1980 |
| f24327f2b05147b197ca34bf13ae3524 | Krubit: Societal Teachings for Do Man... | [Comedy] | 2006 |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.collections.List\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"nrow\":19,\"ncol\":4},\"kotlin_dataframe\":[{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"genres\":[\"Fantasy\",\"Suspenseful\",\"Comedy\"],\"year\":1997},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":[\"Comedy\",\"Jazz\",\"Family\",\"Animation\"],\"year\":2007},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"genres\":[\"Fantasy\",\"Growing up\",\"Magic\"],\"year\":2001},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"genres\":[\"Fantasy\",\"Magic\",\"Suspenseful\"],\"year\":2001},{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair\",\"genres\":[\"Fantasy\"],\"year\":1977},{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"genres\":[\"Fantasy\",\"Superhero\",\"Family\"],\"year\":2008},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":[\"Horror\",\"Existential\"],\"year\":2014},{\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"title\":\"Interplanetary\",\"genres\":[\"Sci-fi\",\"Futuristic\"],\"year\":2014},{\"movieId\":\"9595b771f87f42a3b8dd07d91e7cb328\",\"title\":\"Woods Run\",\"genres\":[\"Family\",\"Drama\"],\"year\":1994},{\"movieId\":\"aa9fc400e068443488b259ea0802a975\",\"title\":\"Anthropod-Dude\",\"genres\":[\"Superhero\",\"Fantasy\",\"Family\",\"Growing up\"],\"year\":2002},{\"movieId\":\"22d20c2ba11d44cab83aceea39dc00bd\",\"title\":\"The Chamber\",\"genres\":[\"Comedy\",\"Drama\"],\"year\":2003},{\"movieId\":\"8cf4d0c1bd7b41fab6af9d92c892141f\",\"title\":\"That Thing About an Iceberg\",\"genres\":[\"Drama\",\"History\",\"Family\",\"Romance\"],\"year\":1997},{\"movieId\":\"c2f3e7588da84684a7d78d6bd8d8e1f4\",\"title\":\"Vehicles\",\"genres\":[\"Animation\",\"Family\"],\"year\":2006},{\"movieId\":\"ce06175106af4105945f245161eac3c7\",\"title\":\"Playthings Tale\",\"genres\":[\"Animation\",\"Family\"],\"year\":1995},{\"movieId\":\"ee28d7e69103485c83e10b8055ef15fb\",\"title\":\"Metal Man 2\",\"genres\":[\"Fantasy\",\"Superhero\",\"Family\"],\"year\":2010},{\"movieId\":\"c32bdeed466f4ec09de828bb4b6fc649\",\"title\":\"Surgeon Odd in the Omniverse of Crazy\",\"genres\":[\"Fantasy\",\"Superhero\",\"Family\",\"Horror\"],\"year\":2022},{\"movieId\":\"d4a325ab648a42c4a2d6f35dfabb387f\",\"title\":\"Bad Dream on Pine Street\",\"genres\":[\"Horror\"],\"year\":1984},{\"movieId\":\"60ebe74947234ddcab49dea1a958faed\",\"title\":\"The Shimmering\",\"genres\":[\"Horror\"],\"year\":1980},{\"movieId\":\"f24327f2b05147b197ca34bf13ae3524\",\"title\":\"Krubit: Societal Teachings for Do Many Good Amazing Country of Uzbekistan\",\"genres\":[\"Comedy\"],\"year\":2006}]}"
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 10
},
{
"cell_type": "markdown",
"id": "eee011ae",
"metadata": {},
"source": [
"_NB: the whole `split` operation is type-safe. We cannot call other operations on DF until we will finish splitting._\n",
"\n",
"`inplace` here means that we want to replace current `genres` column with new content: string -> list of strings."
]
},
{
"cell_type": "markdown",
"id": "5e565279",
"metadata": {},
"source": [
"#### Convert each row with multiple genres into multiple rows having a single genre each\n",
"\n",
"There is a special function right for this task: `explode`!\n",
"And again, despite it being an operation on a column, we can call it on a DF by selecting which columns to explode."
]
},
{
"cell_type": "code",
"id": "92cba457",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:20:58.275907Z",
"start_time": "2025-05-27T14:20:57.906111Z"
}
},
"source": [
"movies\n",
" .filter { year >= 1920 && genres != \"(no genres listed)\" }\n",
" .split { genres }.by(\"|\").inplace()\n",
" .explode { genres }"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | movieId | title | genres | year |
|---|
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | Fantasy | 1997 |
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | Suspenseful | 1997 |
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | Comedy | 1997 |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | Comedy | 2007 |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | Jazz | 2007 |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | Family | 2007 |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | Animation | 2007 |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | Fantasy | 2001 |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | Growing up | 2001 |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | Magic | 2001 |
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | Fantasy | 2001 |
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | Magic | 2001 |
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | Suspenseful | 2001 |
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espair | Fantasy | 1977 |
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | Fantasy | 2008 |
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | Superhero | 2008 |
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | Family | 2008 |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | Horror | 2014 |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | Existential | 2014 |
| c1f0a868aeb44c5ea8d154ec3ca295ac | Interplanetary | Sci-fi | 2014 |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"nrow\":47,\"ncol\":4},\"kotlin_dataframe\":[{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"genres\":\"Fantasy\",\"year\":1997},{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"genres\":\"Suspenseful\",\"year\":1997},{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"genres\":\"Comedy\",\"year\":1997},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":\"Comedy\",\"year\":2007},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":\"Jazz\",\"year\":2007},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":\"Family\",\"year\":2007},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":\"Animation\",\"year\":2007},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"genres\":\"Fantasy\",\"year\":2001},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"genres\":\"Growing up\",\"year\":2001},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"genres\":\"Magic\",\"year\":2001},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"genres\":\"Fantasy\",\"year\":2001},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"genres\":\"Magic\",\"year\":2001},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"genres\":\"Suspenseful\",\"year\":2001},{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair\",\"genres\":\"Fantasy\",\"year\":1977},{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"genres\":\"Fantasy\",\"year\":2008},{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"genres\":\"Superhero\",\"year\":2008},{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"genres\":\"Family\",\"year\":2008},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":\"Horror\",\"year\":2014},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":\"Existential\",\"year\":2014},{\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"title\":\"Interplanetary\",\"genres\":\"Sci-fi\",\"year\":2014}]}"
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 11
},
{
"cell_type": "markdown",
"id": "fba59f32",
"metadata": {},
"source": [
"To make it even easier, we can immediately split the column into lines."
]
},
{
"cell_type": "code",
"id": "744c8f49",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:20:58.564989Z",
"start_time": "2025-05-27T14:20:58.281609Z"
}
},
"source": [
"movies\n",
" .filter { year >= 1920 && genres != \"(no genres listed)\" }\n",
" .split { genres }.by(\"|\").intoRows()"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | movieId | title | genres | year |
|---|
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | Fantasy | 1997 |
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | Suspenseful | 1997 |
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | Comedy | 1997 |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | Comedy | 2007 |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | Jazz | 2007 |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | Family | 2007 |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | Animation | 2007 |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | Fantasy | 2001 |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | Growing up | 2001 |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | Magic | 2001 |
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | Fantasy | 2001 |
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | Magic | 2001 |
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | Suspenseful | 2001 |
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espair | Fantasy | 1977 |
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | Fantasy | 2008 |
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | Superhero | 2008 |
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | Family | 2008 |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | Horror | 2014 |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | Existential | 2014 |
| c1f0a868aeb44c5ea8d154ec3ca295ac | Interplanetary | Sci-fi | 2014 |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"nrow\":47,\"ncol\":4},\"kotlin_dataframe\":[{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"genres\":\"Fantasy\",\"year\":1997},{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"genres\":\"Suspenseful\",\"year\":1997},{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"genres\":\"Comedy\",\"year\":1997},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":\"Comedy\",\"year\":2007},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":\"Jazz\",\"year\":2007},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":\"Family\",\"year\":2007},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":\"Animation\",\"year\":2007},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"genres\":\"Fantasy\",\"year\":2001},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"genres\":\"Growing up\",\"year\":2001},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"genres\":\"Magic\",\"year\":2001},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"genres\":\"Fantasy\",\"year\":2001},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"genres\":\"Magic\",\"year\":2001},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"genres\":\"Suspenseful\",\"year\":2001},{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair\",\"genres\":\"Fantasy\",\"year\":1977},{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"genres\":\"Fantasy\",\"year\":2008},{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"genres\":\"Superhero\",\"year\":2008},{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"genres\":\"Family\",\"year\":2008},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":\"Horror\",\"year\":2014},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":\"Existential\",\"year\":2014},{\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"title\":\"Interplanetary\",\"genres\":\"Sci-fi\",\"year\":2014}]}"
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 12
},
{
"cell_type": "markdown",
"id": "6cfb6144",
"metadata": {},
"source": [
"Now the data is clean enough, analytics can start!\n",
"\n",
"#### Grouping\n",
"\n",
"The first thing we should do here is to group the data by year and genre:"
]
},
{
"cell_type": "code",
"id": "0e7e5b3a",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:20:59.133144Z",
"start_time": "2025-05-27T14:20:58.568486Z"
}
},
"source": [
"movies\n",
" .filter { year >= 1920 && genres != \"(no genres listed)\" }\n",
" .split { genres }.by(\"|\").intoRows()\n",
" .groupBy { year and genres }"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | year | genres | group |
|---|
| 1997 | Fantasy | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | Fantasy | 1997 |
|
| 1997 | Suspenseful | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | Suspenseful | 1997 |
|
| 1997 | Comedy | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | Comedy | 1997 |
|
| 2007 | Comedy | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | Comedy | 2007 |
|
| 2007 | Jazz | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | Jazz | 2007 |
|
| 2007 | Family | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | Family | 2007 |
|
| 2007 | Animation | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | Animation | 2007 |
|
| 2001 | Fantasy | DataFrame [2 x 4]| movieId | title | genres | year |
|---|
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | Fantasy | 2001 | | 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | Fantasy | 2001 |
|
| 2001 | Growing up | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | Growing up | 2001 |
|
| 2001 | Magic | DataFrame [2 x 4]| movieId | title | genres | year |
|---|
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | Magic | 2001 | | 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | Magic | 2001 |
|
| 2001 | Suspenseful | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | Suspenseful | 2001 |
|
| 1977 | Fantasy | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espair | Fantasy | 1977 |
|
| 2008 | Fantasy | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | Fantasy | 2008 |
|
| 2008 | Superhero | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | Superhero | 2008 |
|
| 2008 | Family | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | Family | 2008 |
|
| 2014 | Horror | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | Horror | 2014 |
|
| 2014 | Existential | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | Existential | 2014 |
|
| 2014 | Sci-fi | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| c1f0a868aeb44c5ea8d154ec3ca295ac | Interplanetary | Sci-fi | 2014 |
|
| 2014 | Futuristic | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| c1f0a868aeb44c5ea8d154ec3ca295ac | Interplanetary | Futuristic | 2014 |
|
| 1994 | Family | DataFrame [1 x 4]| movieId | title | genres | year |
|---|
| 9595b771f87f42a3b8dd07d91e7cb328 | Woods Run | Family | 1994 |
|
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"year\",\"genres\",\"group\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"FrameColumn\"}],\"nrow\":45,\"ncol\":3},\"kotlin_dataframe\":[{\"year\":1997,\"genres\":\"Fantasy\",\"group\":{\"data\":[{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"genres\":\"Fantasy\",\"year\":1997}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":1997,\"genres\":\"Suspenseful\",\"group\":{\"data\":[{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"genres\":\"Suspenseful\",\"year\":1997}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":1997,\"genres\":\"Comedy\",\"group\":{\"data\":[{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"genres\":\"Comedy\",\"year\":1997}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":2007,\"genres\":\"Comedy\",\"group\":{\"data\":[{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":\"Comedy\",\"year\":2007}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":2007,\"genres\":\"Jazz\",\"group\":{\"data\":[{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":\"Jazz\",\"year\":2007}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":2007,\"genres\":\"Family\",\"group\":{\"data\":[{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":\"Family\",\"year\":2007}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":2007,\"genres\":\"Animation\",\"group\":{\"data\":[{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":\"Animation\",\"year\":2007}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":2001,\"genres\":\"Fantasy\",\"group\":{\"data\":[{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"genres\":\"Fantasy\",\"year\":2001},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"genres\":\"Fantasy\",\"year\":2001}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":2}}},{\"year\":2001,\"genres\":\"Growing up\",\"group\":{\"data\":[{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"genres\":\"Growing up\",\"year\":2001}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":2001,\"genres\":\"Magic\",\"group\":{\"data\":[{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"genres\":\"Magic\",\"year\":2001},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"genres\":\"Magic\",\"year\":2001}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":2}}},{\"year\":2001,\"genres\":\"Suspenseful\",\"group\":{\"data\":[{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"genres\":\"Suspenseful\",\"year\":2001}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":1977,\"genres\":\"Fantasy\",\"group\":{\"data\":[{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair\",\"genres\":\"Fantasy\",\"year\":1977}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":2008,\"genres\":\"Fantasy\",\"group\":{\"data\":[{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"genres\":\"Fantasy\",\"year\":2008}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":2008,\"genres\":\"Superhero\",\"group\":{\"data\":[{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"genres\":\"Superhero\",\"year\":2008}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":2008,\"genres\":\"Family\",\"group\":{\"data\":[{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"genres\":\"Family\",\"year\":2008}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":2014,\"genres\":\"Horror\",\"group\":{\"data\":[{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":\"Horror\",\"year\":2014}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":2014,\"genres\":\"Existential\",\"group\":{\"data\":[{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":\"Existential\",\"year\":2014}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":2014,\"genres\":\"Sci-fi\",\"group\":{\"data\":[{\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"title\":\"Interplanetary\",\"genres\":\"Sci-fi\",\"year\":2014}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":2014,\"genres\":\"Futuristic\",\"group\":{\"data\":[{\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"title\":\"Interplanetary\",\"genres\":\"Futuristic\",\"year\":2014}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}},{\"year\":1994,\"genres\":\"Family\",\"group\":{\"data\":[{\"movieId\":\"9595b771f87f42a3b8dd07d91e7cb328\",\"title\":\"Woods Run\",\"genres\":\"Family\",\"year\":1994}],\"metadata\":{\"kind\":\"FrameColumn\",\"columns\":[\"movieId\",\"title\",\"genres\",\"year\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"ncol\":4,\"nrow\":1}}}]}"
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 13
},
{
"cell_type": "markdown",
"id": "e155a45b",
"metadata": {},
"source": [
"_Several interesting observations here_\n",
"\n",
"1. We have a synthetic column called `group` here that contains dataframes inside. This means that DataFrames here are first-class citizens. DFs can contain other DFs up to infinite depth!\n",
"2. The returned type from previous is of type `GroupBy`, which allows us to perform special *aggregation* operations\n",
"\n",
"#### Counting movies in groups"
]
},
{
"cell_type": "code",
"id": "99826ece",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:20:59.830212Z",
"start_time": "2025-05-27T14:20:59.138314Z"
}
},
"source": [
"movies\n",
" .filter { year >= 1920 && genres != \"(no genres listed)\" }\n",
" .split { genres }.by(\"|\").intoRows()\n",
" .groupBy { year and genres }.count()\n",
" .sortBy { it[\"count\"].desc() }"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | year | genres | count |
|---|
| 2001 | Fantasy | 2 |
| 2001 | Magic | 2 |
| 1997 | Fantasy | 1 |
| 1997 | Suspenseful | 1 |
| 1997 | Comedy | 1 |
| 2007 | Comedy | 1 |
| 2007 | Jazz | 1 |
| 2007 | Family | 1 |
| 2007 | Animation | 1 |
| 2001 | Growing up | 1 |
| 2001 | Suspenseful | 1 |
| 1977 | Fantasy | 1 |
| 2008 | Fantasy | 1 |
| 2008 | Superhero | 1 |
| 2008 | Family | 1 |
| 2014 | Horror | 1 |
| 2014 | Existential | 1 |
| 2014 | Sci-fi | 1 |
| 2014 | Futuristic | 1 |
| 1994 | Family | 1 |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"year\",\"genres\",\"count\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"nrow\":45,\"ncol\":3},\"kotlin_dataframe\":[{\"year\":2001,\"genres\":\"Fantasy\",\"count\":2},{\"year\":2001,\"genres\":\"Magic\",\"count\":2},{\"year\":1997,\"genres\":\"Fantasy\",\"count\":1},{\"year\":1997,\"genres\":\"Suspenseful\",\"count\":1},{\"year\":1997,\"genres\":\"Comedy\",\"count\":1},{\"year\":2007,\"genres\":\"Comedy\",\"count\":1},{\"year\":2007,\"genres\":\"Jazz\",\"count\":1},{\"year\":2007,\"genres\":\"Family\",\"count\":1},{\"year\":2007,\"genres\":\"Animation\",\"count\":1},{\"year\":2001,\"genres\":\"Growing up\",\"count\":1},{\"year\":2001,\"genres\":\"Suspenseful\",\"count\":1},{\"year\":1977,\"genres\":\"Fantasy\",\"count\":1},{\"year\":2008,\"genres\":\"Fantasy\",\"count\":1},{\"year\":2008,\"genres\":\"Superhero\",\"count\":1},{\"year\":2008,\"genres\":\"Family\",\"count\":1},{\"year\":2014,\"genres\":\"Horror\",\"count\":1},{\"year\":2014,\"genres\":\"Existential\",\"count\":1},{\"year\":2014,\"genres\":\"Sci-fi\",\"count\":1},{\"year\":2014,\"genres\":\"Futuristic\",\"count\":1},{\"year\":1994,\"genres\":\"Family\",\"count\":1}]}"
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 14
},
{
"cell_type": "markdown",
"id": "a1bd1f06",
"metadata": {},
"source": [
"Let's visualize this data and we'll see\n",
"\n",
"\n",
"In other notebooks, you will learn how to build visualizations like these using Kandy!"
]
},
{
"cell_type": "markdown",
"id": "171dddcc",
"metadata": {},
"source": "An alternative way to visualize the data is to build a pivot table. The principle is basically the same."
},
{
"cell_type": "code",
"id": "21e73488",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:21:00.382384Z",
"start_time": "2025-05-27T14:20:59.834426Z"
}
},
"source": [
"movies\n",
" .filter { year >= 1920 && genres != \"(no genres listed)\" }\n",
" .split { genres }.by(\"|\").intoRows()\n",
" .sortBy { year and genres }\n",
" .groupBy { year }.pivot { genres }.count()"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | year | genres | | | | | | | | | | | | | | | |
|---|
| Fantasy | Horror | Drama | Family | Animation | Comedy | History | Romance | Suspenseful | Growing up | Magic | Superhero | Jazz | Existential | Futuristic | Sci-fi |
|---|
| 1977 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1980 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1984 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1994 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1995 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1997 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2001 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 2 | 0 | 0 | 0 | 0 | 0 |
| 2002 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 |
| 2003 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2006 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2007 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| 2008 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| 2010 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| 2014 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 |
| 2022 | 1 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"year\",\"genres\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ColumnGroup\"}],\"nrow\":15,\"ncol\":2},\"kotlin_dataframe\":[{\"year\":1977,\"genres\":{\"data\":{\"Fantasy\":1,\"Horror\":0,\"Drama\":0,\"Family\":0,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":1980,\"genres\":{\"data\":{\"Fantasy\":0,\"Horror\":1,\"Drama\":0,\"Family\":0,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":1984,\"genres\":{\"data\":{\"Fantasy\":0,\"Horror\":1,\"Drama\":0,\"Family\":0,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":1994,\"genres\":{\"data\":{\"Fantasy\":0,\"Horror\":0,\"Drama\":1,\"Family\":1,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":1995,\"genres\":{\"data\":{\"Fantasy\":0,\"Horror\":0,\"Drama\":0,\"Family\":1,\"Animation\":1,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":1997,\"genres\":{\"data\":{\"Fantasy\":1,\"Horror\":0,\"Drama\":1,\"Family\":1,\"Animation\":0,\"Comedy\":1,\"History\":1,\"Romance\":1,\"Suspenseful\":1,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2001,\"genres\":{\"data\":{\"Fantasy\":2,\"Horror\":0,\"Drama\":0,\"Family\":0,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":1,\"Growing up\":1,\"Magic\":2,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2002,\"genres\":{\"data\":{\"Fantasy\":1,\"Horror\":0,\"Drama\":0,\"Family\":1,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":1,\"Magic\":0,\"Superhero\":1,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2003,\"genres\":{\"data\":{\"Fantasy\":0,\"Horror\":0,\"Drama\":1,\"Family\":0,\"Animation\":0,\"Comedy\":1,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2006,\"genres\":{\"data\":{\"Fantasy\":0,\"Horror\":0,\"Drama\":0,\"Family\":1,\"Animation\":1,\"Comedy\":1,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2007,\"genres\":{\"data\":{\"Fantasy\":0,\"Horror\":0,\"Drama\":0,\"Family\":1,\"Animation\":1,\"Comedy\":1,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":1,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2008,\"genres\":{\"data\":{\"Fantasy\":1,\"Horror\":0,\"Drama\":0,\"Family\":1,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":1,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2010,\"genres\":{\"data\":{\"Fantasy\":1,\"Horror\":0,\"Drama\":0,\"Family\":1,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":1,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2014,\"genres\":{\"data\":{\"Fantasy\":0,\"Horror\":1,\"Drama\":0,\"Family\":0,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":1,\"Futuristic\":1,\"Sci-fi\":1},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2022,\"genres\":{\"data\":{\"Fantasy\":1,\"Horror\":1,\"Drama\":0,\"Family\":1,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":1,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}}]}"
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 15
},
{
"cell_type": "markdown",
"id": "9f298812",
"metadata": {},
"source": "`pivot { genres }.count()` can be replaced with a shortcut operation: `pivotCounts { genres }`"
},
{
"cell_type": "code",
"id": "50cbf68b",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:21:00.876869Z",
"start_time": "2025-05-27T14:21:00.386655Z"
}
},
"source": [
"movies\n",
" .filter { year >= 1920 && genres != \"(no genres listed)\" }\n",
" .split { genres }.by(\"|\").intoRows()\n",
" .sortBy { year and genres }\n",
" .groupBy { year }.pivotCounts { genres }"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | year | genres | | | | | | | | | | | | | | | |
|---|
| Fantasy | Horror | Drama | Family | Animation | Comedy | History | Romance | Suspenseful | Growing up | Magic | Superhero | Jazz | Existential | Futuristic | Sci-fi |
|---|
| 1977 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1980 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1984 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1994 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1995 | 0 | 0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1997 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2001 | 2 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 2 | 0 | 0 | 0 | 0 | 0 |
| 2002 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 |
| 2003 | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2006 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 2007 | 0 | 0 | 0 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| 2008 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| 2010 | 1 | 0 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| 2014 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 |
| 2022 | 1 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"year\",\"genres\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ColumnGroup\"}],\"nrow\":15,\"ncol\":2},\"kotlin_dataframe\":[{\"year\":1977,\"genres\":{\"data\":{\"Fantasy\":1,\"Horror\":0,\"Drama\":0,\"Family\":0,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":1980,\"genres\":{\"data\":{\"Fantasy\":0,\"Horror\":1,\"Drama\":0,\"Family\":0,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":1984,\"genres\":{\"data\":{\"Fantasy\":0,\"Horror\":1,\"Drama\":0,\"Family\":0,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":1994,\"genres\":{\"data\":{\"Fantasy\":0,\"Horror\":0,\"Drama\":1,\"Family\":1,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":1995,\"genres\":{\"data\":{\"Fantasy\":0,\"Horror\":0,\"Drama\":0,\"Family\":1,\"Animation\":1,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":1997,\"genres\":{\"data\":{\"Fantasy\":1,\"Horror\":0,\"Drama\":1,\"Family\":1,\"Animation\":0,\"Comedy\":1,\"History\":1,\"Romance\":1,\"Suspenseful\":1,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2001,\"genres\":{\"data\":{\"Fantasy\":2,\"Horror\":0,\"Drama\":0,\"Family\":0,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":1,\"Growing up\":1,\"Magic\":2,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2002,\"genres\":{\"data\":{\"Fantasy\":1,\"Horror\":0,\"Drama\":0,\"Family\":1,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":1,\"Magic\":0,\"Superhero\":1,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2003,\"genres\":{\"data\":{\"Fantasy\":0,\"Horror\":0,\"Drama\":1,\"Family\":0,\"Animation\":0,\"Comedy\":1,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2006,\"genres\":{\"data\":{\"Fantasy\":0,\"Horror\":0,\"Drama\":0,\"Family\":1,\"Animation\":1,\"Comedy\":1,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2007,\"genres\":{\"data\":{\"Fantasy\":0,\"Horror\":0,\"Drama\":0,\"Family\":1,\"Animation\":1,\"Comedy\":1,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":1,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2008,\"genres\":{\"data\":{\"Fantasy\":1,\"Horror\":0,\"Drama\":0,\"Family\":1,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":1,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2010,\"genres\":{\"data\":{\"Fantasy\":1,\"Horror\":0,\"Drama\":0,\"Family\":1,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":1,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2014,\"genres\":{\"data\":{\"Fantasy\":0,\"Horror\":1,\"Drama\":0,\"Family\":0,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":0,\"Jazz\":0,\"Existential\":1,\"Futuristic\":1,\"Sci-fi\":1},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}},{\"year\":2022,\"genres\":{\"data\":{\"Fantasy\":1,\"Horror\":1,\"Drama\":0,\"Family\":1,\"Animation\":0,\"Comedy\":0,\"History\":0,\"Romance\":0,\"Suspenseful\":0,\"Growing up\":0,\"Magic\":0,\"Superhero\":1,\"Jazz\":0,\"Existential\":0,\"Futuristic\":0,\"Sci-fi\":0},\"metadata\":{\"kind\":\"ColumnGroup\",\"columns\":[\"Fantasy\",\"Horror\",\"Drama\",\"Family\",\"Animation\",\"Comedy\",\"History\",\"Romance\",\"Suspenseful\",\"Growing up\",\"Magic\",\"Superhero\",\"Jazz\",\"Existential\",\"Futuristic\",\"Sci-fi\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}]}}}]}"
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 16
},
{
"cell_type": "markdown",
"id": "c612a76f",
"metadata": {},
"source": [
"Drama has been the most popular all these years! I was a bit shocked when I discovered it.\n",
"\n",
"Now let's move to the next part.\n",
"\n",
"### Find the most tagged movie\n",
"\n",
"Now you're familiar with the basics, we can skip several things, but here is what we're going to do:\n",
"\n",
"1. Read tags\n",
"2. Join movies with tags\n",
"3. Group by movie id\n",
"4. Aggregate all tags into a set (to remove duplicates, if any)\n",
"5. Get 10 top-tagged movies\n",
"6. ???\n",
"7. PROFIT\n",
"\n",
"First, let's read tags' data and explore its schema."
]
},
{
"cell_type": "code",
"id": "77d58a44085dd8e3",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:26:52.443812Z",
"start_time": "2025-05-27T14:26:52.279869Z"
}
},
"source": [
"val tags = DataFrame.read(\"../../../idea-examples/movies/src/main/resources/tags.csv\")\n",
"tags"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | userId | movieId | tag | timestamp |
|---|
| 3 | 9595b771f87f42a3b8dd07d91e7cb328 | classic | 1439472355 |
| 3 | 6aa0d26a483148998c250b9c80ddf550 | sci-fi | 1439472256 |
| 4 | f24327f2b05147b197ca34bf13ae3524 | dark comedy | 1573943598 |
| 4 | ae916bc4844a4bb7b42b70d9573d05cd | great dialogue | 1573943604 |
| 4 | f24327f2b05147b197ca34bf13ae3524 | so bad it's good | 1573943455 |
| 4 | d4a325ab648a42c4a2d6f35dfabb387f | tense | 1573943077 |
| 4 | ae916bc4844a4bb7b42b70d9573d05cd | artificial intelligence | 1573942979 |
| 4 | ae916bc4844a4bb7b42b70d9573d05cd | philosophical | 1573943033 |
| 4 | c1f0a868aeb44c5ea8d154ec3ca295ac | tense | 1573943042 |
| 4 | 22d20c2ba11d44cab83aceea39dc00bd | so bad it's good | 1573942965 |
| 4 | 8cf4d0c1bd7b41fab6af9d92c892141f | cliche | 1573943721 |
| 4 | 2bb29b3a245e434fa80542e711fd2cee | musical | 1573943714 |
| 4 | 60ebe74947234ddcab49dea1a958faed | horror | 1573945163 |
| 4 | 2bb29b3a245e434fa80542e711fd2cee | unpredictable | 1573945171 |
| 19 | 9b30aff7943f44579e92c261f3adc193 | Oscar (Best Supporting Actress) | 1446909853 |
| 19 | 43d02fb064514ff3bd30d1e3a7398357 | adventure | 1445286141 |
| 19 | f44ceb4771504342bb856d76c112d5a6 | fantasy | 1445286144 |
| 19 | c1f0a868aeb44c5ea8d154ec3ca295ac | post-apocalyptic | 1445286136 |
| 20 | 2a1ba1fc5caf492a80188e032995843e | bah | 1155082282 |
| 84 | f24327f2b05147b197ca34bf13ae3524 | documentary | 1549387432 |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"userId\",\"movieId\",\"tag\",\"timestamp\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"nrow\":38,\"ncol\":4},\"kotlin_dataframe\":[{\"userId\":3,\"movieId\":\"9595b771f87f42a3b8dd07d91e7cb328\",\"tag\":\"classic\",\"timestamp\":1439472355},{\"userId\":3,\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"tag\":\"sci-fi\",\"timestamp\":1439472256},{\"userId\":4,\"movieId\":\"f24327f2b05147b197ca34bf13ae3524\",\"tag\":\"dark comedy\",\"timestamp\":1573943598},{\"userId\":4,\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"tag\":\"great dialogue\",\"timestamp\":1573943604},{\"userId\":4,\"movieId\":\"f24327f2b05147b197ca34bf13ae3524\",\"tag\":\"so bad it's good\",\"timestamp\":1573943455},{\"userId\":4,\"movieId\":\"d4a325ab648a42c4a2d6f35dfabb387f\",\"tag\":\"tense\",\"timestamp\":1573943077},{\"userId\":4,\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"tag\":\"artificial intelligence\",\"timestamp\":1573942979},{\"userId\":4,\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"tag\":\"philosophical\",\"timestamp\":1573943033},{\"userId\":4,\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"tag\":\"tense\",\"timestamp\":1573943042},{\"userId\":4,\"movieId\":\"22d20c2ba11d44cab83aceea39dc00bd\",\"tag\":\"so bad it's good\",\"timestamp\":1573942965},{\"userId\":4,\"movieId\":\"8cf4d0c1bd7b41fab6af9d92c892141f\",\"tag\":\"cliche\",\"timestamp\":1573943721},{\"userId\":4,\"movieId\":\"2bb29b3a245e434fa80542e711fd2cee\",\"tag\":\"musical\",\"timestamp\":1573943714},{\"userId\":4,\"movieId\":\"60ebe74947234ddcab49dea1a958faed\",\"tag\":\"horror\",\"timestamp\":1573945163},{\"userId\":4,\"movieId\":\"2bb29b3a245e434fa80542e711fd2cee\",\"tag\":\"unpredictable\",\"timestamp\":1573945171},{\"userId\":19,\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"tag\":\"Oscar (Best Supporting Actress)\",\"timestamp\":1446909853},{\"userId\":19,\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"tag\":\"adventure\",\"timestamp\":1445286141},{\"userId\":19,\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"tag\":\"fantasy\",\"timestamp\":1445286144},{\"userId\":19,\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"tag\":\"post-apocalyptic\",\"timestamp\":1445286136},{\"userId\":20,\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"tag\":\"bah\",\"timestamp\":1155082282},{\"userId\":84,\"movieId\":\"f24327f2b05147b197ca34bf13ae3524\",\"tag\":\"documentary\",\"timestamp\":1549387432}]}"
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 25
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:26:59.200830Z",
"start_time": "2025-05-27T14:26:59.152566Z"
}
},
"cell_type": "code",
"source": "tags.schema()",
"id": "8c4bde5b",
"outputs": [
{
"data": {
"text/plain": [
"userId: Int\n",
"movieId: String\n",
"tag: String\n",
"timestamp: Int"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 26
},
{
"cell_type": "markdown",
"id": "a8e7c9f3",
"metadata": {},
"source": [
"Nothing too shocking here.\n",
"We get `tag`, `userId`, `movieId`, and `timestamp`.\n",
"We're not interested in `userId` and `timestamp` this time. Instead, we should join on `movieId`."
]
},
{
"cell_type": "code",
"id": "81769f72",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:21:02.041238Z",
"start_time": "2025-05-27T14:21:01.512756Z"
}
},
"source": [
"val moviesWithTags = movies.leftJoin(tags) { movieId }\n",
"moviesWithTags"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | movieId | title | genres | year | userId | tag | timestamp |
|---|
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | Fantasy|Suspenseful|Comedy | 1997 | 19 | Oscar (Best Supporting Actress) | 1446909853 |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | Comedy|Jazz|Family|Animation | 2007 | 20 | bah | 1155082282 |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | Fantasy|Growing up|Magic | 2001 | 19 | fantasy | 1445286144 |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | Fantasy|Growing up|Magic | 2001 | 91 | based on book | 1414248543 |
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | Fantasy|Magic|Suspenseful | 2001 | 19 | adventure | 1445286141 |
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espair | Fantasy | 1977 | 3 | sci-fi | 1439472256 |
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espair | Fantasy | 1977 | 87 | sci-fi | 1522676660 |
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espair | Fantasy | 1977 | 87 | science fiction | 1522676703 |
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espair | Fantasy | 1977 | 87 | space | 1522676664 |
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | Fantasy|Superhero|Family | 2008 | 87 | bad science | 1522676752 |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | Horror|Existential | 2014 | 4 | great dialogue | 1573943604 |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | Horror|Existential | 2014 | 4 | artificial intelligence | 1573942979 |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | Horror|Existential | 2014 | 4 | philosophical | 1573943033 |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | Horror|Existential | 2014 | 87 | android(s)/cyborg(s) | 1542309549 |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | Horror|Existential | 2014 | 87 | artificial intelligence | 1542309599 |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | Horror|Existential | 2014 | 87 | philosophical issues | 1522676687 |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | Horror|Existential | 2014 | 91 | thought-provoking | 1415131203 |
| c1f0a868aeb44c5ea8d154ec3ca295ac | Interplanetary | Sci-fi|Futuristic | 2014 | 4 | tense | 1573943042 |
| c1f0a868aeb44c5ea8d154ec3ca295ac | Interplanetary | Sci-fi|Futuristic | 2014 | 19 | post-apocalyptic | 1445286136 |
| c1f0a868aeb44c5ea8d154ec3ca295ac | Interplanetary | Sci-fi|Futuristic | 2014 | 87 | sci-fi | 1542308464 |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"movieId\",\"title\",\"genres\",\"year\",\"userId\",\"tag\",\"timestamp\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int?\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String?\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int?\"}],\"nrow\":41,\"ncol\":7},\"kotlin_dataframe\":[{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"genres\":\"Fantasy|Suspenseful|Comedy\",\"year\":1997,\"userId\":19,\"tag\":\"Oscar (Best Supporting Actress)\",\"timestamp\":1446909853},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"genres\":\"Comedy|Jazz|Family|Animation\",\"year\":2007,\"userId\":20,\"tag\":\"bah\",\"timestamp\":1155082282},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"genres\":\"Fantasy|Growing up|Magic\",\"year\":2001,\"userId\":19,\"tag\":\"fantasy\",\"timestamp\":1445286144},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"genres\":\"Fantasy|Growing up|Magic\",\"year\":2001,\"userId\":91,\"tag\":\"based on book\",\"timestamp\":1414248543},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"genres\":\"Fantasy|Magic|Suspenseful\",\"year\":2001,\"userId\":19,\"tag\":\"adventure\",\"timestamp\":1445286141},{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair\",\"genres\":\"Fantasy\",\"year\":1977,\"userId\":3,\"tag\":\"sci-fi\",\"timestamp\":1439472256},{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair\",\"genres\":\"Fantasy\",\"year\":1977,\"userId\":87,\"tag\":\"sci-fi\",\"timestamp\":1522676660},{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair\",\"genres\":\"Fantasy\",\"year\":1977,\"userId\":87,\"tag\":\"science fiction\",\"timestamp\":1522676703},{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair\",\"genres\":\"Fantasy\",\"year\":1977,\"userId\":87,\"tag\":\"space\",\"timestamp\":1522676664},{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"genres\":\"Fantasy|Superhero|Family\",\"year\":2008,\"userId\":87,\"tag\":\"bad science\",\"timestamp\":1522676752},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":\"Horror|Existential\",\"year\":2014,\"userId\":4,\"tag\":\"great dialogue\",\"timestamp\":1573943604},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":\"Horror|Existential\",\"year\":2014,\"userId\":4,\"tag\":\"artificial intelligence\",\"timestamp\":1573942979},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":\"Horror|Existential\",\"year\":2014,\"userId\":4,\"tag\":\"philosophical\",\"timestamp\":1573943033},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":\"Horror|Existential\",\"year\":2014,\"userId\":87,\"tag\":\"android(s)/cyborg(s)\",\"timestamp\":1542309549},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":\"Horror|Existential\",\"year\":2014,\"userId\":87,\"tag\":\"artificial intelligence\",\"timestamp\":1542309599},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":\"Horror|Existential\",\"year\":2014,\"userId\":87,\"tag\":\"philosophical issues\",\"timestamp\":1522676687},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"genres\":\"Horror|Existential\",\"year\":2014,\"userId\":91,\"tag\":\"thought-provoking\",\"timestamp\":1415131203},{\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"title\":\"Interplanetary\",\"genres\":\"Sci-fi|Futuristic\",\"year\":2014,\"userId\":4,\"tag\":\"tense\",\"timestamp\":1573943042},{\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"title\":\"Interplanetary\",\"genres\":\"Sci-fi|Futuristic\",\"year\":2014,\"userId\":19,\"tag\":\"post-apocalyptic\",\"timestamp\":1445286136},{\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"title\":\"Interplanetary\",\"genres\":\"Sci-fi|Futuristic\",\"year\":2014,\"userId\":87,\"tag\":\"sci-fi\",\"timestamp\":1542308464}]}"
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 18
},
{
"cell_type": "markdown",
"id": "19add254",
"metadata": {},
"source": [
"Quite simple, right? Just like usual SQL syntax, with auto-completion in the lambda returning the JOIN predicate.\n",
"\n",
"Now let's group and aggregate it"
]
},
{
"cell_type": "code",
"id": "12733c1c",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:21:02.324280Z",
"start_time": "2025-05-27T14:21:02.046207Z"
}
},
"source": [
"moviesWithTags\n",
" .groupBy { movieId }\n",
" .aggregate {\n",
" title.first() into \"title\"\n",
" tag.dropNulls().toSet() into \"tags\"\n",
" }"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | movieId | title | tags |
|---|
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | [Oscar (Best Supporting Actress)] |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | [bah] |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | [fantasy, based on book] |
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | [adventure] |
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espair | [sci-fi, science fiction, space] |
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | [bad science] |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | [great dialogue, artificial intellige... |
| c1f0a868aeb44c5ea8d154ec3ca295ac | Interplanetary | [tense, post-apocalyptic, sci-fi, apo... |
| 9595b771f87f42a3b8dd07d91e7cb328 | Woods Run | [classic] |
| aa9fc400e068443488b259ea0802a975 | Anthropod-Dude | [quirky] |
| 22d20c2ba11d44cab83aceea39dc00bd | The Chamber | [so bad it's good] |
| 8cf4d0c1bd7b41fab6af9d92c892141f | That Thing About an Iceberg | [cliche, romantic] |
| c2f3e7588da84684a7d78d6bd8d8e1f4 | Vehicles | [] |
| ce06175106af4105945f245161eac3c7 | Playthings Tale | [] |
| ee28d7e69103485c83e10b8055ef15fb | Metal Man 2 | [franchise, sci-fi, science fiction] |
| c32bdeed466f4ec09de828bb4b6fc649 | Surgeon Odd in the Omniverse of Crazy | [] |
| d4a325ab648a42c4a2d6f35dfabb387f | Bad Dream on Pine Street | [tense] |
| 60ebe74947234ddcab49dea1a958faed | The Shimmering | [horror] |
| f24327f2b05147b197ca34bf13ae3524 | Krubit: Societal Teachings for Do Man... | [dark comedy, so bad it's good, docum... |
| 2bb29b3a245e434fa80542e711fd2cee | This is No Movie | [musical, unpredictable] |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"movieId\",\"title\",\"tags\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.collections.Set\"}],\"nrow\":20,\"ncol\":3},\"kotlin_dataframe\":[{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"tags\":\"[Oscar (Best Supporting Actress)]\"},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"tags\":\"[bah]\"},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"tags\":\"[fantasy, based on book]\"},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"tags\":\"[adventure]\"},{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair\",\"tags\":\"[sci-fi, science fiction, space]\"},{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"tags\":\"[bad science]\"},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"tags\":\"[great dialogue, artificial intelligence, philosophical, android(s)/cyborg(s), philosophical issues, thought-provoking]\"},{\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"title\":\"Interplanetary\",\"tags\":\"[tense, post-apocalyptic, sci-fi, apocalypse, space travel, visually appealing]\"},{\"movieId\":\"9595b771f87f42a3b8dd07d91e7cb328\",\"title\":\"Woods Run\",\"tags\":\"[classic]\"},{\"movieId\":\"aa9fc400e068443488b259ea0802a975\",\"title\":\"Anthropod-Dude\",\"tags\":\"[quirky]\"},{\"movieId\":\"22d20c2ba11d44cab83aceea39dc00bd\",\"title\":\"The Chamber\",\"tags\":\"[so bad it's good]\"},{\"movieId\":\"8cf4d0c1bd7b41fab6af9d92c892141f\",\"title\":\"That Thing About an Iceberg\",\"tags\":\"[cliche, romantic]\"},{\"movieId\":\"c2f3e7588da84684a7d78d6bd8d8e1f4\",\"title\":\"Vehicles\",\"tags\":\"[]\"},{\"movieId\":\"ce06175106af4105945f245161eac3c7\",\"title\":\"Playthings Tale\",\"tags\":\"[]\"},{\"movieId\":\"ee28d7e69103485c83e10b8055ef15fb\",\"title\":\"Metal Man 2\",\"tags\":\"[franchise, sci-fi, science fiction]\"},{\"movieId\":\"c32bdeed466f4ec09de828bb4b6fc649\",\"title\":\"Surgeon Odd in the Omniverse of Crazy\",\"tags\":\"[]\"},{\"movieId\":\"d4a325ab648a42c4a2d6f35dfabb387f\",\"title\":\"Bad Dream on Pine Street\",\"tags\":\"[tense]\"},{\"movieId\":\"60ebe74947234ddcab49dea1a958faed\",\"title\":\"The Shimmering\",\"tags\":\"[horror]\"},{\"movieId\":\"f24327f2b05147b197ca34bf13ae3524\",\"title\":\"Krubit: Societal Teachings for Do Many Good Amazing Country of Uzbekistan\",\"tags\":\"[dark comedy, so bad it's good, documentary]\"},{\"movieId\":\"2bb29b3a245e434fa80542e711fd2cee\",\"title\":\"This is No Movie\",\"tags\":\"[musical, unpredictable]\"}]}"
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 19
},
{
"cell_type": "markdown",
"id": "5492b30c",
"metadata": {},
"source": [
"Nothing new in grouping, but here we find the new syntax of aggregation. \n",
"\n",
"First, we **know** that when we group by `movieId`, every `movieId` will match exactly one title. This means that in every group we can select any `title`;\n",
"`first()` is one of the ways to achieve this goal. Potentially the fastest one.\n",
"\n",
"Second, we gather all tags into one set. Notice how we work with `tag` column as if it was just a collection. Miraculous, isn't it?\n",
"Of course, in reality it's not a collection, but it's an object of type `DataColumn` which allows exporting data into some collections.\n",
"And on this \"collection\" we already can do any transformations we want."
]
},
{
"cell_type": "markdown",
"id": "4af6896a",
"metadata": {},
"source": [
"Some `groupBy` aggregations can be simplified with shortcut functions. We can include `title` in key columns for grouping, so that our aggregation will reduce to a collection of all unique non-null `tag` values per every group. For such simple aggregation we can replace general `aggregate` operation with `values`."
]
},
{
"cell_type": "code",
"id": "33006264",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:21:02.644146Z",
"start_time": "2025-05-27T14:21:02.327177Z"
}
},
"source": [
"moviesWithTags\n",
" .groupBy { movieId and title }.values(dropNA = true, distinct = true) {\n",
" tag into \"tags\"\n",
" }"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | movieId | title | tags |
|---|
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | [Oscar (Best Supporting Actress)] |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | [bah] |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | [fantasy, based on book] |
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | [adventure] |
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espair | [sci-fi, science fiction, space] |
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | [bad science] |
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | [great dialogue, artificial intellige... |
| c1f0a868aeb44c5ea8d154ec3ca295ac | Interplanetary | [tense, post-apocalyptic, sci-fi, apo... |
| 9595b771f87f42a3b8dd07d91e7cb328 | Woods Run | [classic] |
| aa9fc400e068443488b259ea0802a975 | Anthropod-Dude | [quirky] |
| 22d20c2ba11d44cab83aceea39dc00bd | The Chamber | [so bad it's good] |
| 8cf4d0c1bd7b41fab6af9d92c892141f | That Thing About an Iceberg | [cliche, romantic] |
| c2f3e7588da84684a7d78d6bd8d8e1f4 | Vehicles | [ ] |
| ce06175106af4105945f245161eac3c7 | Playthings Tale | [ ] |
| ee28d7e69103485c83e10b8055ef15fb | Metal Man 2 | [franchise, sci-fi, science fiction] |
| c32bdeed466f4ec09de828bb4b6fc649 | Surgeon Odd in the Omniverse of Crazy | [ ] |
| d4a325ab648a42c4a2d6f35dfabb387f | Bad Dream on Pine Street | [tense] |
| 60ebe74947234ddcab49dea1a958faed | The Shimmering | [horror] |
| f24327f2b05147b197ca34bf13ae3524 | Krubit: Societal Teachings for Do Man... | [dark comedy, so bad it's good, docum... |
| 2bb29b3a245e434fa80542e711fd2cee | This is No Movie | [musical, unpredictable] |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"movieId\",\"title\",\"tags\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.collections.List\"}],\"nrow\":20,\"ncol\":3},\"kotlin_dataframe\":[{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"tags\":[\"Oscar (Best Supporting Actress)\"]},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"tags\":[\"bah\"]},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"tags\":[\"fantasy\",\"based on book\"]},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"tags\":[\"adventure\"]},{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair\",\"tags\":[\"sci-fi\",\"science fiction\",\"space\"]},{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"tags\":[\"bad science\"]},{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"tags\":[\"great dialogue\",\"artificial intelligence\",\"philosophical\",\"android(s)/cyborg(s)\",\"philosophical issues\",\"thought-provoking\"]},{\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"title\":\"Interplanetary\",\"tags\":[\"tense\",\"post-apocalyptic\",\"sci-fi\",\"apocalypse\",\"space travel\",\"visually appealing\"]},{\"movieId\":\"9595b771f87f42a3b8dd07d91e7cb328\",\"title\":\"Woods Run\",\"tags\":[\"classic\"]},{\"movieId\":\"aa9fc400e068443488b259ea0802a975\",\"title\":\"Anthropod-Dude\",\"tags\":[\"quirky\"]},{\"movieId\":\"22d20c2ba11d44cab83aceea39dc00bd\",\"title\":\"The Chamber\",\"tags\":[\"so bad it's good\"]},{\"movieId\":\"8cf4d0c1bd7b41fab6af9d92c892141f\",\"title\":\"That Thing About an Iceberg\",\"tags\":[\"cliche\",\"romantic\"]},{\"movieId\":\"c2f3e7588da84684a7d78d6bd8d8e1f4\",\"title\":\"Vehicles\",\"tags\":[]},{\"movieId\":\"ce06175106af4105945f245161eac3c7\",\"title\":\"Playthings Tale\",\"tags\":[]},{\"movieId\":\"ee28d7e69103485c83e10b8055ef15fb\",\"title\":\"Metal Man 2\",\"tags\":[\"franchise\",\"sci-fi\",\"science fiction\"]},{\"movieId\":\"c32bdeed466f4ec09de828bb4b6fc649\",\"title\":\"Surgeon Odd in the Omniverse of Crazy\",\"tags\":[]},{\"movieId\":\"d4a325ab648a42c4a2d6f35dfabb387f\",\"title\":\"Bad Dream on Pine Street\",\"tags\":[\"tense\"]},{\"movieId\":\"60ebe74947234ddcab49dea1a958faed\",\"title\":\"The Shimmering\",\"tags\":[\"horror\"]},{\"movieId\":\"f24327f2b05147b197ca34bf13ae3524\",\"title\":\"Krubit: Societal Teachings for Do Many Good Amazing Country of Uzbekistan\",\"tags\":[\"dark comedy\",\"so bad it's good\",\"documentary\"]},{\"movieId\":\"2bb29b3a245e434fa80542e711fd2cee\",\"title\":\"This is No Movie\",\"tags\":[\"musical\",\"unpredictable\"]}]}"
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 20
},
{
"cell_type": "markdown",
"id": "17c342b7",
"metadata": {},
"source": "Now we should find most tagged movies. For that we should sort by the number of tags in descending order."
},
{
"cell_type": "code",
"id": "83b17906",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:21:03.069616Z",
"start_time": "2025-05-27T14:21:02.648280Z"
}
},
"source": [
"moviesWithTags\n",
" .groupBy { movieId and title }.values(dropNA = true, distinct = true) { tag into \"tags\" }\n",
" .sortByDesc { expr { \"tags\">().count() } }\n",
" .take(10)\n"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | movieId | title | tags |
|---|
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | [great dialogue, artificial intellige... |
| c1f0a868aeb44c5ea8d154ec3ca295ac | Interplanetary | [tense, post-apocalyptic, sci-fi, apo... |
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espair | [sci-fi, science fiction, space] |
| ee28d7e69103485c83e10b8055ef15fb | Metal Man 2 | [franchise, sci-fi, science fiction] |
| f24327f2b05147b197ca34bf13ae3524 | Krubit: Societal Teachings for Do Man... | [dark comedy, so bad it's good, docum... |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | [fantasy, based on book] |
| 8cf4d0c1bd7b41fab6af9d92c892141f | That Thing About an Iceberg | [cliche, romantic] |
| 2bb29b3a245e434fa80542e711fd2cee | This is No Movie | [musical, unpredictable] |
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | [Oscar (Best Supporting Actress)] |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | [bah] |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"movieId\",\"title\",\"tags\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.collections.List\"}],\"nrow\":10,\"ncol\":3},\"kotlin_dataframe\":[{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"tags\":[\"great dialogue\",\"artificial intelligence\",\"philosophical\",\"android(s)/cyborg(s)\",\"philosophical issues\",\"thought-provoking\"]},{\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"title\":\"Interplanetary\",\"tags\":[\"tense\",\"post-apocalyptic\",\"sci-fi\",\"apocalypse\",\"space travel\",\"visually appealing\"]},{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair\",\"tags\":[\"sci-fi\",\"science fiction\",\"space\"]},{\"movieId\":\"ee28d7e69103485c83e10b8055ef15fb\",\"title\":\"Metal Man 2\",\"tags\":[\"franchise\",\"sci-fi\",\"science fiction\"]},{\"movieId\":\"f24327f2b05147b197ca34bf13ae3524\",\"title\":\"Krubit: Societal Teachings for Do Many Good Amazing Country of Uzbekistan\",\"tags\":[\"dark comedy\",\"so bad it's good\",\"documentary\"]},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"tags\":[\"fantasy\",\"based on book\"]},{\"movieId\":\"8cf4d0c1bd7b41fab6af9d92c892141f\",\"title\":\"That Thing About an Iceberg\",\"tags\":[\"cliche\",\"romantic\"]},{\"movieId\":\"2bb29b3a245e434fa80542e711fd2cee\",\"title\":\"This is No Movie\",\"tags\":[\"musical\",\"unpredictable\"]},{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"tags\":[\"Oscar (Best Supporting Actress)\"]},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"tags\":[\"bah\"]}]}"
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 21
},
{
"cell_type": "markdown",
"id": "2bae07b4",
"metadata": {},
"source": "OK, indeed, there are lots of tags :) Let's output the number of tags into a separate column"
},
{
"cell_type": "code",
"id": "27c8ea28",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:21:03.842907Z",
"start_time": "2025-05-27T14:21:03.073754Z"
}
},
"source": [
"val tagsPerMovie = moviesWithTags\n",
" .groupBy { movieId and title }.values(dropNA = true, distinct = true) { tag into \"tags\" }\n",
" .add(\"tagsCount\") {\n",
" \"tags\">().count()\n",
" }\n",
" .sortByDesc(\"tagsCount\")\n",
"tagsPerMovie"
],
"outputs": [
{
"data": {
"text/html": [
" \n",
" \n",
" \n",
" \n",
" \n",
" \n",
" | movieId | title | tags | tagsCount |
|---|
| ae916bc4844a4bb7b42b70d9573d05cd | In Automata | [great dialogue, artificial intellige... | 6 |
| c1f0a868aeb44c5ea8d154ec3ca295ac | Interplanetary | [tense, post-apocalyptic, sci-fi, apo... | 6 |
| 6aa0d26a483148998c250b9c80ddf550 | Sun Conflicts: Part IV: A Novel Espair | [sci-fi, science fiction, space] | 3 |
| ee28d7e69103485c83e10b8055ef15fb | Metal Man 2 | [franchise, sci-fi, science fiction] | 3 |
| f24327f2b05147b197ca34bf13ae3524 | Krubit: Societal Teachings for Do Man... | [dark comedy, so bad it's good, docum... | 3 |
| f44ceb4771504342bb856d76c112d5a6 | Magical School Boy and the Rock of Wi... | [fantasy, based on book] | 2 |
| 8cf4d0c1bd7b41fab6af9d92c892141f | That Thing About an Iceberg | [cliche, romantic] | 2 |
| 2bb29b3a245e434fa80542e711fd2cee | This is No Movie | [musical, unpredictable] | 2 |
| 9b30aff7943f44579e92c261f3adc193 | Women in Black | [Oscar (Best Supporting Actress)] | 1 |
| 2a1ba1fc5caf492a80188e032995843e | Bumblebee Movie | [bah] | 1 |
| 43d02fb064514ff3bd30d1e3a7398357 | Master of the Jewlery: The Company of... | [adventure] | 1 |
| eace16e59ce24eff90bf8924eb6a926c | The Outstanding Bulk | [bad science] | 1 |
| 9595b771f87f42a3b8dd07d91e7cb328 | Woods Run | [classic] | 1 |
| aa9fc400e068443488b259ea0802a975 | Anthropod-Dude | [quirky] | 1 |
| 22d20c2ba11d44cab83aceea39dc00bd | The Chamber | [so bad it's good] | 1 |
| d4a325ab648a42c4a2d6f35dfabb387f | Bad Dream on Pine Street | [tense] | 1 |
| 60ebe74947234ddcab49dea1a958faed | The Shimmering | [horror] | 1 |
| c2f3e7588da84684a7d78d6bd8d8e1f4 | Vehicles | [ ] | 0 |
| ce06175106af4105945f245161eac3c7 | Playthings Tale | [ ] | 0 |
| c32bdeed466f4ec09de828bb4b6fc649 | Surgeon Odd in the Omniverse of Crazy | [ ] | 0 |
\n",
" \n",
" \n",
" "
],
"application/kotlindataframe+json": "{\"$version\":\"2.1.1\",\"metadata\":{\"columns\":[\"movieId\",\"title\",\"tags\",\"tagsCount\"],\"types\":[{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.String\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.collections.List\"},{\"kind\":\"ValueColumn\",\"type\":\"kotlin.Int\"}],\"nrow\":20,\"ncol\":4},\"kotlin_dataframe\":[{\"movieId\":\"ae916bc4844a4bb7b42b70d9573d05cd\",\"title\":\"In Automata\",\"tags\":[\"great dialogue\",\"artificial intelligence\",\"philosophical\",\"android(s)/cyborg(s)\",\"philosophical issues\",\"thought-provoking\"],\"tagsCount\":6},{\"movieId\":\"c1f0a868aeb44c5ea8d154ec3ca295ac\",\"title\":\"Interplanetary\",\"tags\":[\"tense\",\"post-apocalyptic\",\"sci-fi\",\"apocalypse\",\"space travel\",\"visually appealing\"],\"tagsCount\":6},{\"movieId\":\"6aa0d26a483148998c250b9c80ddf550\",\"title\":\"Sun Conflicts: Part IV: A Novel Espair\",\"tags\":[\"sci-fi\",\"science fiction\",\"space\"],\"tagsCount\":3},{\"movieId\":\"ee28d7e69103485c83e10b8055ef15fb\",\"title\":\"Metal Man 2\",\"tags\":[\"franchise\",\"sci-fi\",\"science fiction\"],\"tagsCount\":3},{\"movieId\":\"f24327f2b05147b197ca34bf13ae3524\",\"title\":\"Krubit: Societal Teachings for Do Many Good Amazing Country of Uzbekistan\",\"tags\":[\"dark comedy\",\"so bad it's good\",\"documentary\"],\"tagsCount\":3},{\"movieId\":\"f44ceb4771504342bb856d76c112d5a6\",\"title\":\"Magical School Boy and the Rock of Wise Men\",\"tags\":[\"fantasy\",\"based on book\"],\"tagsCount\":2},{\"movieId\":\"8cf4d0c1bd7b41fab6af9d92c892141f\",\"title\":\"That Thing About an Iceberg\",\"tags\":[\"cliche\",\"romantic\"],\"tagsCount\":2},{\"movieId\":\"2bb29b3a245e434fa80542e711fd2cee\",\"title\":\"This is No Movie\",\"tags\":[\"musical\",\"unpredictable\"],\"tagsCount\":2},{\"movieId\":\"9b30aff7943f44579e92c261f3adc193\",\"title\":\"Women in Black\",\"tags\":[\"Oscar (Best Supporting Actress)\"],\"tagsCount\":1},{\"movieId\":\"2a1ba1fc5caf492a80188e032995843e\",\"title\":\"Bumblebee Movie\",\"tags\":[\"bah\"],\"tagsCount\":1},{\"movieId\":\"43d02fb064514ff3bd30d1e3a7398357\",\"title\":\"Master of the Jewlery: The Company of the Jewel\",\"tags\":[\"adventure\"],\"tagsCount\":1},{\"movieId\":\"eace16e59ce24eff90bf8924eb6a926c\",\"title\":\"The Outstanding Bulk\",\"tags\":[\"bad science\"],\"tagsCount\":1},{\"movieId\":\"9595b771f87f42a3b8dd07d91e7cb328\",\"title\":\"Woods Run\",\"tags\":[\"classic\"],\"tagsCount\":1},{\"movieId\":\"aa9fc400e068443488b259ea0802a975\",\"title\":\"Anthropod-Dude\",\"tags\":[\"quirky\"],\"tagsCount\":1},{\"movieId\":\"22d20c2ba11d44cab83aceea39dc00bd\",\"title\":\"The Chamber\",\"tags\":[\"so bad it's good\"],\"tagsCount\":1},{\"movieId\":\"d4a325ab648a42c4a2d6f35dfabb387f\",\"title\":\"Bad Dream on Pine Street\",\"tags\":[\"tense\"],\"tagsCount\":1},{\"movieId\":\"60ebe74947234ddcab49dea1a958faed\",\"title\":\"The Shimmering\",\"tags\":[\"horror\"],\"tagsCount\":1},{\"movieId\":\"c2f3e7588da84684a7d78d6bd8d8e1f4\",\"title\":\"Vehicles\",\"tags\":[],\"tagsCount\":0},{\"movieId\":\"ce06175106af4105945f245161eac3c7\",\"title\":\"Playthings Tale\",\"tags\":[],\"tagsCount\":0},{\"movieId\":\"c32bdeed466f4ec09de828bb4b6fc649\",\"title\":\"Surgeon Odd in the Omniverse of Crazy\",\"tags\":[],\"tagsCount\":0}]}"
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 22
},
{
"cell_type": "code",
"id": "01cbbed1",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:21:04.042081Z",
"start_time": "2025-05-27T14:21:03.850806Z"
}
},
"source": [
"tagsPerMovie.tagsCount.sum()"
],
"outputs": [
{
"data": {
"text/plain": [
"36"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 23
},
{
"cell_type": "code",
"id": "accea0d3",
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-27T14:21:04.150335Z",
"start_time": "2025-05-27T14:21:04.046709Z"
}
},
"source": [
"tagsPerMovie[0].tags"
],
"outputs": [
{
"data": {
"text/plain": [
"[great dialogue, artificial intelligence, philosophical, android(s)/cyborg(s), philosophical issues, thought-provoking]"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"execution_count": 24
},
{
"cell_type": "markdown",
"id": "c309c91b",
"metadata": {},
"source": [
"And yes, I should admit, some of these tags are crazy.\n",
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Kotlin",
"language": "kotlin",
"name": "kotlin"
},
"ktnbPluginMetadata": {
"projectLibraries": []
},
"language_info": {
"codemirror_mode": "text/x-kotlin",
"file_extension": ".kt",
"mimetype": "text/x-kotlin",
"name": "kotlin",
"nbconvert_exporter": "",
"pygments_lexer": "kotlin",
"version": "1.9.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}