|
1 |
| -[//]: # (title: Getting started) |
| 1 | +[//]: # (title: Get started with Kotlin DataFrame) |
2 | 2 |
|
3 |
| -The Kotlin DataFrame library is a JVM Kotlin library for in-memory data manipulation. |
| 3 | +The Kotlin DataFrame library gives you the power to manipulate data in your Kotlin projects. |
4 | 4 |
|
5 |
| - |
| 5 | +This page explains how to: |
| 6 | +* Set up the Kotlin DataFrame library in an IntelliJ IDEA project with Gradle. |
| 7 | +* Import and manipulate data. |
| 8 | +* Export data. |
6 | 9 |
|
7 |
| -## Installation |
8 |
| -First, pick up the latest version of the Kotlin DataFrame library [here](https://search.maven.org/artifact/org.jetbrains.kotlinx/dataframe). |
9 |
| -* If you wish to play with data in interactive mode, setup [Kotlin Kernel for Jupyter](installation.md#jupyter-notebook) and run DataFrame there |
10 |
| -* If you have some JVM project, just add a dependency on the Kotlin DataFrame library like it's described on [Maven Central search](https://search.maven.org/artifact/org.jetbrains.kotlinx/dataframe) site |
| 10 | +To use the Kotlin DataFrame library with Jupyter notebooks or Datalore, follow the instructions on our [Installation page](installation.md). |
11 | 11 |
|
12 |
| -## Examples |
13 |
| -Hope that this documentation will help you to implement all the things you want to do with your data. To get inspiration, take a look at [examples](https://github.com/Kotlin/dataframe/tree/master/examples) folder. [Puzzles](https://github.com/Kotlin/dataframe/blob/master/examples/jupyter-notebooks/puzzles/40%20puzzles.ipynb) will quickly familiarize you with the power of DataFrame, and other notebooks and projects will show you some applications of DataFrame in practical data analysis. |
| 12 | +## Install Kotlin |
14 | 13 |
|
15 |
| -## Feedback and contributing |
16 |
| -If you found a bug, or have an idea for a new feature, please [file an issue](https://github.com/Kotlin/dataframe/issues/new) in DataFrame GitHub repository. |
| 14 | +Kotlin is included in each IntelliJ IDEA release. |
| 15 | +Download and install [IntelliJ IDEA](https://www.jetbrains.com/idea/download/) to start using Kotlin. |
17 | 16 |
|
18 |
| -If you wish to contribute, you're welcome! Choose an issue you like, let us know that you're working on it, and prepare a [pull request](https://github.com/Kotlin/dataframe/pulls). We'll review and merge it if everything goes well. |
| 17 | +## Create Kotlin project |
19 | 18 |
|
20 |
| -You can also give us feedback or ask a question in [#datascience](https://kotlinlang.slack.com/archives/C4W52CFEZ) channel of a Kotlin Slack. |
| 19 | +1. In IntelliJ IDEA, select **File** | **New** | **Project**. |
| 20 | +2. In the panel on the left, select **New Project**. |
| 21 | +3. Name the new project and change its location, if necessary. |
21 | 22 |
|
22 |
| -Good luck! |
| 23 | + > Select the **Create Git repository** checkbox to place the new project under version control. You can enable this |
| 24 | + > later at any time. |
| 25 | + > |
| 26 | + {type="tip"} |
| 27 | + |
| 28 | +4. From the **Language** list, select **Kotlin**. |
| 29 | +5. Select the **Gradle** build system. |
| 30 | +6. From the **JDK list**, select the [JDK](https://www.oracle.com/java/technologies/downloads/) that you want to use in |
| 31 | + your project. The minimum supported version is JDK 8. |
| 32 | + * If the JDK is installed on your computer, but not defined in the IDE, select **Add JDK** and specify the path to the |
| 33 | + JDK home directory. |
| 34 | + * If you don't have the necessary JDK on your computer, select **Download JDK**. |
| 35 | +7. From the **Gradle DSL** list, select **Kotlin** or **Groovy**. |
| 36 | +8. Select the **Add sample code** checkbox to create a file with a sample `"Hello World!"` application. |
| 37 | +9. Click **Create**. |
| 38 | + |
| 39 | +You have successfully created a project with Gradle. |
| 40 | + |
| 41 | +### Update Gradle dependencies |
| 42 | + |
| 43 | +In your Gradle build file (`build.gradle.kts`), add the Kotlin DataFrame library as a dependency: |
| 44 | + |
| 45 | +<tabs> |
| 46 | +<tab title="Kotlin DSL"> |
| 47 | + |
| 48 | +```kotlin |
| 49 | +dependencies { |
| 50 | + implementation("org.jetbrains.kotlinx:dataframe:%dataFrameVersion%") |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +</tab> |
| 55 | + |
| 56 | +<tab title="Groovy DSL"> |
| 57 | + |
| 58 | +```kotlin |
| 59 | +dependencies { |
| 60 | + implementation 'org.jetbrains.kotlinx:dataframe:%dataFrameVersion%' |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +</tab> |
| 65 | + |
| 66 | +</tabs> |
| 67 | + |
| 68 | +### Add imports |
| 69 | + |
| 70 | +In `src/main/kotlin/Main.kt`, add the following imports at the top of the file: |
| 71 | + |
| 72 | +```kotlin |
| 73 | +import org.jetbrains.kotlinx.dataframe.DataFrame |
| 74 | +import org.jetbrains.kotlinx.dataframe.io.* |
| 75 | +import org.jetbrains.kotlinx.dataframe.api.* |
| 76 | +``` |
| 77 | + |
| 78 | +## Import data |
| 79 | + |
| 80 | +Download and save our file to the root directory of your project: |
| 81 | + |
| 82 | +<res resource-id="movie-sample-data"/> |
| 83 | + |
| 84 | +Delete the `println()` functions and comments from your main function in `Main.kt`. |
| 85 | + |
| 86 | +To import the movie sample data into a data frame and print it, inside your main function in `Main.kt`, add the following code: |
| 87 | + |
| 88 | +```kotlin |
| 89 | + // Import your data to a data frame |
| 90 | + var df = DataFrame.read("movies.csv") |
| 91 | + |
| 92 | + // Print your data frame |
| 93 | + df.print() |
| 94 | +``` |
| 95 | + |
| 96 | +## Manipulate data |
| 97 | + |
| 98 | +To print some information about your data frame and sort your data, add the following additional lines of code: |
| 99 | + |
| 100 | +```kotlin |
| 101 | + // Print some information about the data frame |
| 102 | + println(df.columnNames()) // Print column names |
| 103 | + println(df.count()) // Print number of rows |
| 104 | + |
| 105 | + // Sort your data alphabetically by title |
| 106 | + df = df.sortBy("title") |
| 107 | + |
| 108 | + // Filter your data so that only comedy films remain, and print |
| 109 | + df = df.filter { "genres"<String>().contains("Comedy") } |
| 110 | + df.print() |
| 111 | +``` |
| 112 | + |
| 113 | +## Export data |
| 114 | + |
| 115 | +To export the current version of your data frame in CSV format, add the following additional lines of code and run `Main.kt`. |
| 116 | + |
| 117 | +```kotlin |
| 118 | + // Export your manipulated data to CSV format |
| 119 | + df.writeCSV("movies-by-title.csv") |
| 120 | +``` |
| 121 | + |
| 122 | + |
| 123 | +<code-block lang="console" collapsed-title="Example terminal output" collapsible="true"> |
| 124 | + movieId title genres |
| 125 | + 0 9b30aff7943f44579e92c261f3adc193 Women in Black (1997) Fantasy|Suspenseful|Comedy |
| 126 | + 1 2a1ba1fc5caf492a80188e032995843e Bumblebee Movie (2007) Comedy|Jazz|Family|Animation |
| 127 | + 2 f44ceb4771504342bb856d76c112d5a6 Magical School Boy and the Rock of Wi... Fantasy|Growing up|Magic |
| 128 | + 3 43d02fb064514ff3bd30d1e3a7398357 Master of the Jewlery: The Company of... Fantasy|Magic|Suspenseful |
| 129 | + 4 6aa0d26a483148998c250b9c80ddf550 Sun Conflicts: Part IV: A Novel Espai... Fantasy |
| 130 | + 5 eace16e59ce24eff90bf8924eb6a926c The Outstanding Bulk (2008) Fantasy|Superhero|Family |
| 131 | + 6 ae916bc4844a4bb7b42b70d9573d05cd In Automata (2014) Horror|Existential |
| 132 | + 7 c1f0a868aeb44c5ea8d154ec3ca295ac Interplanetary (2014) Sci-fi|Futuristic |
| 133 | + 8 9595b771f87f42a3b8dd07d91e7cb328 Woods Run (1994) Family|Drama |
| 134 | + 9 aa9fc400e068443488b259ea0802a975 Anthropod-Dude (2002) Superhero|Fantasy|Family|Growing up |
| 135 | + 10 22d20c2ba11d44cab83aceea39dc00bd The Chamber (2003) Comedy|Drama |
| 136 | + 11 8cf4d0c1bd7b41fab6af9d92c892141f That Thing About an Iceberg (1997) Drama|History|Family|Romance |
| 137 | + 12 c2f3e7588da84684a7d78d6bd8d8e1f4 Vehicles (2006) Animation|Family |
| 138 | + 13 ce06175106af4105945f245161eac3c7 Playthings Tale (1995) Animation|Family |
| 139 | + 14 ee28d7e69103485c83e10b8055ef15fb Metal Man 2 (2010) Fantasy|Superhero|Family |
| 140 | + 15 c32bdeed466f4ec09de828bb4b6fc649 Surgeon Odd in the Omniverse of Crazy... Fantasy|Superhero|Family|Horror |
| 141 | + 16 d4a325ab648a42c4a2d6f35dfabb387f Bad Dream on Pine Street (1984) Horror |
| 142 | + 17 60ebe74947234ddcab49dea1a958faed The Shimmering (1980) Horror |
| 143 | + 18 f24327f2b05147b197ca34bf13ae3524 Krubit: Societal Teachings for Do Man... Comedy |
| 144 | + 19 2bb29b3a245e434fa80542e711fd2cee This is No Movie (1950) (no genres listed) |
| 145 | +[movieId, title, genres] |
| 146 | +20 |
| 147 | +movieId title genres |
| 148 | +0 2a1ba1fc5caf492a80188e032995843e Bumblebee Movie (2007) Comedy|Jazz|Family|Animation |
| 149 | +1 f24327f2b05147b197ca34bf13ae3524 Krubit: Societal Teachings for Do Man... Comedy |
| 150 | +2 22d20c2ba11d44cab83aceea39dc00bd The Chamber (2003) Comedy|Drama |
| 151 | +3 9b30aff7943f44579e92c261f3adc193 Women in Black (1997) Fantasy|Suspenseful|Comedy |
| 152 | +</code-block> |
| 153 | + |
| 154 | +Congratulations! You have successfully used the Kotlin DataFrame library to import, manipulate and export data. |
| 155 | + |
| 156 | +## Next steps |
| 157 | +* Learn more about how to [import and export data](io.md) |
| 158 | +* Learn about our different [access APIs](apiLevels.md) |
| 159 | +* Explore the many different [operations that you can perform](operations.md) |
0 commit comments