init research
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
|
||||
|
||||
plugins {
|
||||
application
|
||||
kotlin("jvm")
|
||||
|
||||
id("org.jetbrains.kotlinx.dataframe")
|
||||
|
||||
// only mandatory if `kotlin.dataframe.add.ksp=false` in gradle.properties
|
||||
id("com.google.devtools.ksp")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal() // in case of local dataframe development
|
||||
}
|
||||
|
||||
application.mainClass = "org.jetbrains.kotlinx.dataframe.examples.movies.MoviesWithDataClassKt"
|
||||
|
||||
dependencies {
|
||||
// implementation("org.jetbrains.kotlinx:dataframe:X.Y.Z")
|
||||
implementation(project(":"))
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
jvmTarget = JvmTarget.JVM_1_8
|
||||
freeCompilerArgs.add("-Xjdk-release=8")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<JavaCompile> {
|
||||
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
|
||||
targetCompatibility = JavaVersion.VERSION_1_8.toString()
|
||||
options.release.set(8)
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package org.jetbrains.kotlinx.dataframe.examples.movies
|
||||
|
||||
import org.jetbrains.kotlinx.dataframe.DataFrame
|
||||
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
|
||||
import org.jetbrains.kotlinx.dataframe.api.*
|
||||
import org.jetbrains.kotlinx.dataframe.io.*
|
||||
|
||||
/**
|
||||
* movieId title genres
|
||||
* 0 9b30aff7943f44579e92c261f3adc193 Women in Black (1997) Fantasy|Suspenseful|Comedy
|
||||
* 1 2a1ba1fc5caf492a80188e032995843e Bumblebee Movie (2007) Comedy|Jazz|Family|Animation
|
||||
*/
|
||||
@DataSchema
|
||||
interface Movie {
|
||||
val movieId: String
|
||||
val title: String
|
||||
val genres: String
|
||||
}
|
||||
|
||||
private const val pathToCsv = "examples/idea-examples/movies/src/main/resources/movies.csv"
|
||||
// Uncomment this line if you want to copy-paste and run the code in your project without downloading the file
|
||||
//private const val pathToCsv = "https://raw.githubusercontent.com/Kotlin/dataframe/master/examples/idea-examples/movies/src/main/resources/movies.csv"
|
||||
|
||||
fun main() {
|
||||
// This example shows how to the use extension properties API to address columns in different operations
|
||||
// https://kotlin.github.io/dataframe/apilevels.html
|
||||
|
||||
// Add the Gradle plugin and run `assemble`
|
||||
// check the README https://github.com/Kotlin/dataframe?tab=readme-ov-file#setup
|
||||
val step1 = DataFrame
|
||||
.read(pathToCsv).convertTo<Movie>()
|
||||
.split { genres }.by("|").inplace()
|
||||
.split { title }.by {
|
||||
listOf<Any>(
|
||||
"""\s*\(\d{4}\)\s*$""".toRegex().replace(it, ""),
|
||||
"\\d{4}".toRegex().findAll(it).lastOrNull()?.value?.toIntOrNull() ?: -1,
|
||||
)
|
||||
}.into("title", "year")
|
||||
.explode("genres")
|
||||
step1.print()
|
||||
|
||||
/**
|
||||
* Data is parsed and prepared for aggregation
|
||||
* movieId title year genres
|
||||
* 0 9b30aff7943f44579e92c261f3adc193 Women in Black 1997 Fantasy
|
||||
* 1 9b30aff7943f44579e92c261f3adc193 Women in Black 1997 Suspenseful
|
||||
* 2 9b30aff7943f44579e92c261f3adc193 Women in Black 1997 Comedy
|
||||
* 3 2a1ba1fc5caf492a80188e032995843e Bumblebee Movie 2007 Comedy
|
||||
* 4 2a1ba1fc5caf492a80188e032995843e Bumblebee Movie 2007 Jazz
|
||||
* 5 2a1ba1fc5caf492a80188e032995843e Bumblebee Movie 2007 Family
|
||||
* 6 2a1ba1fc5caf492a80188e032995843e Bumblebee Movie 2007 Animation
|
||||
*/
|
||||
val step2 = step1
|
||||
.filter { "year"<Int>() >= 0 && genres != "(no genres listed)" }
|
||||
.groupBy("year")
|
||||
.sortBy("year")
|
||||
.pivot("genres", inward = false)
|
||||
.aggregate {
|
||||
count() into "count"
|
||||
mean() into "mean"
|
||||
}
|
||||
|
||||
step2.print(10)
|
||||
// Discover the final reshaped data in an interactive HTML table
|
||||
// step2.toStandaloneHTML().openInBrowser()
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
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 Wise Men (2001),Fantasy|Growing up|Magic
|
||||
43d02fb064514ff3bd30d1e3a7398357,Master of the Jewlery: The Company of the Jewel (2001),Fantasy|Magic|Suspenseful
|
||||
6aa0d26a483148998c250b9c80ddf550,Sun Conflicts: Part IV: A Novel Espair (1977),Fantasy
|
||||
eace16e59ce24eff90bf8924eb6a926c,The Outstanding Bulk (2008),Fantasy|Superhero|Family
|
||||
ae916bc4844a4bb7b42b70d9573d05cd,In Automata (2014),Horror|Existential
|
||||
c1f0a868aeb44c5ea8d154ec3ca295ac,Interplanetary (2014),Sci-fi|Futuristic
|
||||
9595b771f87f42a3b8dd07d91e7cb328,Woods Run (1994),Family|Drama
|
||||
aa9fc400e068443488b259ea0802a975,Anthropod-Dude (2002),Superhero|Fantasy|Family|Growing up
|
||||
22d20c2ba11d44cab83aceea39dc00bd,The Chamber (2003),Comedy|Drama
|
||||
8cf4d0c1bd7b41fab6af9d92c892141f,That Thing About an Iceberg (1997),Drama|History|Family|Romance
|
||||
c2f3e7588da84684a7d78d6bd8d8e1f4,Vehicles (2006),Animation|Family
|
||||
ce06175106af4105945f245161eac3c7,Playthings Tale (1995),Animation|Family
|
||||
ee28d7e69103485c83e10b8055ef15fb,Metal Man 2 (2010),Fantasy|Superhero|Family
|
||||
c32bdeed466f4ec09de828bb4b6fc649,Surgeon Odd in the Omniverse of Crazy (2022),Fantasy|Superhero|Family|Horror
|
||||
d4a325ab648a42c4a2d6f35dfabb387f,Bad Dream on Pine Street (1984),Horror
|
||||
60ebe74947234ddcab49dea1a958faed,The Shimmering (1980),Horror
|
||||
f24327f2b05147b197ca34bf13ae3524,Krubit: Societal Teachings for Do Many Good Amazing Country of Uzbekistan (2006),Comedy
|
||||
2bb29b3a245e434fa80542e711fd2cee,This is No Movie (1950),(no genres listed)
|
||||
|
+7790
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,39 @@
|
||||
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
|
||||
87,c1f0a868aeb44c5ea8d154ec3ca295ac,sci-fi,1542308464
|
||||
87,ae916bc4844a4bb7b42b70d9573d05cd,android(s)/cyborg(s),1542309549
|
||||
87,c1f0a868aeb44c5ea8d154ec3ca295ac,apocalypse,1542309703
|
||||
87,ae916bc4844a4bb7b42b70d9573d05cd,artificial intelligence,1542309599
|
||||
87,ee28d7e69103485c83e10b8055ef15fb,franchise,1542309536
|
||||
87,ee28d7e69103485c83e10b8055ef15fb,sci-fi,1542308408
|
||||
87,ee28d7e69103485c83e10b8055ef15fb,science fiction,1542308395
|
||||
87,eace16e59ce24eff90bf8924eb6a926c,bad science,1522676752
|
||||
87,ae916bc4844a4bb7b42b70d9573d05cd,philosophical issues,1522676687
|
||||
87,6aa0d26a483148998c250b9c80ddf550,sci-fi,1522676660
|
||||
87,6aa0d26a483148998c250b9c80ddf550,science fiction,1522676703
|
||||
87,6aa0d26a483148998c250b9c80ddf550,space,1522676664
|
||||
87,c1f0a868aeb44c5ea8d154ec3ca295ac,space travel,1522676685
|
||||
87,c1f0a868aeb44c5ea8d154ec3ca295ac,visually appealing,1522676682
|
||||
91,aa9fc400e068443488b259ea0802a975,quirky,1415914797
|
||||
91,8cf4d0c1bd7b41fab6af9d92c892141f,romantic,1415131173
|
||||
91,ae916bc4844a4bb7b42b70d9573d05cd,thought-provoking,1415131203
|
||||
91,f44ceb4771504342bb856d76c112d5a6,based on book,1414248543
|
||||
|
Reference in New Issue
Block a user