@@ -2,21 +2,14 @@ package org.jetbrains.kotlinx.dataframe.examples.movies
2
2
3
3
import org.jetbrains.kotlinx.dataframe.DataFrame
4
4
import 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.*
19
7
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
+ */
20
13
@DataSchema
21
14
interface Movie {
22
15
val movieId: String
@@ -25,9 +18,16 @@ interface Movie {
25
18
}
26
19
27
20
private 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"
28
23
29
24
fun 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
31
31
.read(pathToCsv).convertTo<Movie >()
32
32
.split { genres }.by(" |" ).inplace()
33
33
.split { title }.by {
@@ -37,12 +37,30 @@ fun main() {
37
37
)
38
38
}.into(" title" , " year" )
39
39
.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
40
54
.filter { " year" <Int >() >= 0 && genres != " (no genres listed)" }
41
55
.groupBy(" year" )
42
56
.sortBy(" year" )
43
57
.pivot(" genres" , inward = false )
44
58
.aggregate {
45
59
count() into " count"
46
60
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()
48
66
}
0 commit comments