Dataframe 0.14 Help

merge

Merges several columns into a single column.

Reverse operation to split

merge { columns } [.notNull()] .by(delimeter) | .by { merger } [.into(column) | .intoList() ] merger: (DataRow).List<T> -> Any
// Merge two columns into one column "fullName" df.merge { name.firstName and name.lastName }.by(" ").into("fullName")

merger accepts a List of collected values for every row typed by their common type:

df.merge { name.firstName and name.lastName } .by { it[0] + " (" + it[1].uppercase() + ")" } .into("fullName")

When heterogeneous columns are merged, they may need to be cast to valid types in merger:

df.merge { name.firstName and age and isHappy } .by { "${it[0]} aged ${it[1]} is " + (if (it[2] as Boolean) "" else "not ") + "happy" } .into("status")

By default, when no delimeter or merger is specified, values will be merged into the List:

df.merge { colsOf<Number>() }.into("data")

Merged column values can also be exported to List:

// Merge data from two columns into List<String> df.merge { name.firstName and name.lastName }.by(",").intoList()
Last modified: 27 September 2024