Get started with Kotlin DataFrame on Gradle
Edit page Last modified: 14 January 2025This page explains how to:
Set up the Kotlin DataFrame library in an IntelliJ IDEA project with Gradle.
Import and manipulate data.
Export data.
Create a Kotlin project
In IntelliJ IDEA, select File | New | Project.
In the panel on the left, select New Project.
Name the new project and change its location, if necessary.
tip
Select the Create Git repository checkbox to place the new project under version control. You can enable this later at any time.
From the Language list, select Kotlin.
Select the Gradle build system.
From the JDK list, select the JDK that you want to use in your project. The minimum supported version is JDK 8.
If the JDK is installed on your computer, but not defined in the IDE, select Add JDK and specify the path to the JDK home directory.
If you don't have the necessary JDK on your computer, select Download JDK.
From the Gradle DSL list, select Kotlin or Groovy.
Select the Add sample code checkbox to create a file with a sample
"Hello World!"
application.Click Create.
You have successfully created a project with Gradle.
Update Gradle dependencies
In your Gradle build file (build.gradle.kts
), add the Kotlin DataFrame library as a dependency:
plugins {
id("org.jetbrains.kotlinx.dataframe") version "0.15.0"
}
dependencies {
implementation("org.jetbrains.kotlinx:dataframe:0.15.0")
}
plugins {
id "org.jetbrains.kotlinx.dataframe" version "0.15.0"
}
dependencies {
implementation 'org.jetbrains.kotlinx:dataframe:0.15.0'
}
Add imports
In src/main/kotlin/Main.kt
, add the following imports at the top of the file:
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.io.*
import org.jetbrains.kotlinx.dataframe.api.*
Import data
Download the file movies.csv
from here to the root directory of your project:
Delete the println()
functions and comments from your main function in Main.kt
.
To import the movie sample data into a data frame and print it inside your main function in Main.kt
, add the following code:
// Import your data to a data frame
var df = DataFrame.read("movies.csv")
// Print your data frame
df.print()
Manipulate data
To print some information about your data frame and sort your data, add the following additional lines of code:
// Print some information about the data frame
println(df.columnNames()) // Print column names
println(df.count()) // Print number of rows
// Sort your data alphabetically by title
df = df.sortBy("title")
// Filter your data so that only comedy films remain, and print
df = df.filter { "genres"<String>().contains("Comedy") }
df.print()
Export data
To export the current version of your data frame in CSV format, add the following additional lines of code and run Main.kt
.
// Export your manipulated data to CSV format
df.writeCSV("movies-by-title.csv")
Example terminal output
{...}
Congratulations! You have successfully used the Kotlin DataFrame library to import, manipulate and export data.
Next steps
Learn more about how to import and export data
Learn about our different access APIs
Explore the many different operations that you can perform