Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to read csv to nested data class hierarchy? #114

Closed
ionox0 opened this issue May 23, 2022 · 1 comment
Closed

Possible to read csv to nested data class hierarchy? #114

ionox0 opened this issue May 23, 2022 · 1 comment

Comments

@ionox0
Copy link

ionox0 commented May 23, 2022

Is it possible to have something like this:

data class Parent(
  val child: Child
)

data class Child(
  val age: Int
)

val df = DataFrame
        .readCSV(inputCsv)
        .convertTo<Parent>()

Maybe there is some way to specify how the fields are nested using the headers = parameter?

@koperagen
Copy link
Collaborator

Hi! I would split the problem into two parts:

  1. Read CSV into a dataframe with nested hierarchy. Here we have two options:
    i) read flat CSV and use https://kotlin.github.io/dataframe/group.html to create nesting.
    ii) if cells of your CSV contain JSON values, then dataframe will read them into ColumnGroup (value is object) or FrameColumn (value is array of objects). It's not mentioned in the current version of the documentation, i will publish an update :)
  2. Get a list of a data class instances from the dataframe with nested hierarchy: https://kotlin.github.io/dataframe/collectionsinterop.html#interop-with-data-classes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants