@@ -2,21 +2,14 @@ package org.jetbrains.kotlinx.dataframe.examples.movies
22
33import org.jetbrains.kotlinx.dataframe.DataFrame
44import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
5- import org.jetbrains.kotlinx.dataframe.api.by
6- import org.jetbrains.kotlinx.dataframe.api.convertTo
7- import org.jetbrains.kotlinx.dataframe.api.count
8- import org.jetbrains.kotlinx.dataframe.api.explode
9- import org.jetbrains.kotlinx.dataframe.api.filter
10- import org.jetbrains.kotlinx.dataframe.api.groupBy
11- import org.jetbrains.kotlinx.dataframe.api.inplace
12- import org.jetbrains.kotlinx.dataframe.api.into
13- import org.jetbrains.kotlinx.dataframe.api.mean
14- import org.jetbrains.kotlinx.dataframe.api.pivot
15- import org.jetbrains.kotlinx.dataframe.api.print
16- import org.jetbrains.kotlinx.dataframe.api.sortBy
17- import org.jetbrains.kotlinx.dataframe.api.split
18- import org.jetbrains.kotlinx.dataframe.io.read
5+ import org.jetbrains.kotlinx.dataframe.api.*
6+ import org.jetbrains.kotlinx.dataframe.io.*
197
8+ /* *
9+ * movieId title genres
10+ * 0 9b30aff7943f44579e92c261f3adc193 Women in Black (1997) Fantasy|Suspenseful|Comedy
11+ * 1 2a1ba1fc5caf492a80188e032995843e Bumblebee Movie (2007) Comedy|Jazz|Family|Animation
12+ */
2013@DataSchema
2114interface Movie {
2215 val movieId: String
@@ -25,9 +18,16 @@ interface Movie {
2518}
2619
2720private const val pathToCsv = " examples/idea-examples/movies/src/main/resources/movies.csv"
21+ // Uncomment this line if you want to copy-paste and run the code in your project without downloading the file
22+ // private const val pathToCsv = "https://raw.githubusercontent.com/Kotlin/dataframe/master/examples/idea-examples/movies/src/main/resources/movies.csv"
2823
2924fun main () {
30- DataFrame
25+ // This example shows how to the use extension properties API to address columns in different operations
26+ // https://kotlin.github.io/dataframe/apilevels.html
27+
28+ // Add the Gradle plugin and run `assemble`
29+ // check the README https://github.com/Kotlin/dataframe?tab=readme-ov-file#setup
30+ val step1 = DataFrame
3131 .read(pathToCsv).convertTo<Movie >()
3232 .split { genres }.by(" |" ).inplace()
3333 .split { title }.by {
@@ -37,12 +37,30 @@ fun main() {
3737 )
3838 }.into(" title" , " year" )
3939 .explode(" genres" )
40+ step1.print ()
41+
42+ /* *
43+ * Data is parsed and prepared for aggregation
44+ * movieId title year genres
45+ * 0 9b30aff7943f44579e92c261f3adc193 Women in Black 1997 Fantasy
46+ * 1 9b30aff7943f44579e92c261f3adc193 Women in Black 1997 Suspenseful
47+ * 2 9b30aff7943f44579e92c261f3adc193 Women in Black 1997 Comedy
48+ * 3 2a1ba1fc5caf492a80188e032995843e Bumblebee Movie 2007 Comedy
49+ * 4 2a1ba1fc5caf492a80188e032995843e Bumblebee Movie 2007 Jazz
50+ * 5 2a1ba1fc5caf492a80188e032995843e Bumblebee Movie 2007 Family
51+ * 6 2a1ba1fc5caf492a80188e032995843e Bumblebee Movie 2007 Animation
52+ */
53+ val step2 = step1
4054 .filter { " year" <Int >() >= 0 && genres != " (no genres listed)" }
4155 .groupBy(" year" )
4256 .sortBy(" year" )
4357 .pivot(" genres" , inward = false )
4458 .aggregate {
4559 count() into " count"
4660 mean() into " mean"
47- }.print (10 )
61+ }
62+
63+ step2.print (10 )
64+ // Discover the final reshaped data in an interactive HTML table
65+ // step2.toStandaloneHTML().openInBrowser()
4866}
0 commit comments