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")
movieId title genres
0 9b30aff7943f44579e92c261f3adc193 Women in Black (1997) Fantasy|Suspenseful|Comedy
1 2a1ba1fc5caf492a80188e032995843e Bumblebee Movie (2007) Comedy|Jazz|Family|Animation
2 f44ceb4771504342bb856d76c112d5a6 Magical School Boy and the Rock of Wi... Fantasy|Growing up|Magic
3 43d02fb064514ff3bd30d1e3a7398357 Master of the Jewlery: The Company of... Fantasy|Magic|Suspenseful
4 6aa0d26a483148998c250b9c80ddf550 Sun Conflicts: Part IV: A Novel Espai... Fantasy
5 eace16e59ce24eff90bf8924eb6a926c The Outstanding Bulk (2008) Fantasy|Superhero|Family
6 ae916bc4844a4bb7b42b70d9573d05cd In Automata (2014) Horror|Existential
7 c1f0a868aeb44c5ea8d154ec3ca295ac Interplanetary (2014) Sci-fi|Futuristic
8 9595b771f87f42a3b8dd07d91e7cb328 Woods Run (1994) Family|Drama
9 aa9fc400e068443488b259ea0802a975 Anthropod-Dude (2002) Superhero|Fantasy|Family|Growing up
10 22d20c2ba11d44cab83aceea39dc00bd The Chamber (2003) Comedy|Drama
11 8cf4d0c1bd7b41fab6af9d92c892141f That Thing About an Iceberg (1997) Drama|History|Family|Romance
12 c2f3e7588da84684a7d78d6bd8d8e1f4 Vehicles (2006) Animation|Family
13 ce06175106af4105945f245161eac3c7 Playthings Tale (1995) Animation|Family
14 ee28d7e69103485c83e10b8055ef15fb Metal Man 2 (2010) Fantasy|Superhero|Family
15 c32bdeed466f4ec09de828bb4b6fc649 Surgeon Odd in the Omniverse of Crazy... Fantasy|Superhero|Family|Horror
16 d4a325ab648a42c4a2d6f35dfabb387f Bad Dream on Pine Street (1984) Horror
17 60ebe74947234ddcab49dea1a958faed The Shimmering (1980) Horror
18 f24327f2b05147b197ca34bf13ae3524 Krubit: Societal Teachings for Do Man... Comedy
19 2bb29b3a245e434fa80542e711fd2cee This is No Movie (1950) (no genres listed)
[movieId, title, genres]
20
movieId title genres
0 2a1ba1fc5caf492a80188e032995843e Bumblebee Movie (2007) Comedy|Jazz|Family|Animation
1 f24327f2b05147b197ca34bf13ae3524 Krubit: Societal Teachings for Do Man... Comedy
2 22d20c2ba11d44cab83aceea39dc00bd The Chamber (2003) Comedy|Drama
3 9b30aff7943f44579e92c261f3adc193 Women in Black (1997) Fantasy|Suspenseful|Comedy
Congratulations! You have successfully used the Kotlin DataFrame library to import, manipulate and export data.