Closed devdanke closed 3 years ago
By design data frames are immutable but clearly, you can do
var df = iris
df = iris.addColumn("Species"){ "bla"}
to replace an existing column.
Concerning your use-case you could use NA aware conversions
sleepData.addColumn("foo") { it["vore"].toInts() }
which are provided for all supported types.
I still wonder how to make the API more approachable with more docs, a cheatsheet, some extended faq....
Closed because of inactivity. Feel welcome to reopen if needed.
It would be nice if there were a replaceColumn() method for cases where a numeric column gets typed as a string column. For instance, in a CSV file I wrangle, they sometimes use "" instead of zero for missing values. I agree with Krangl for classifying it as StringCol. I'd like an easy way to clean-up the values so it can be a number column.
Here's an extension method that lets me replace a column:
` fun DataFrame.replaceColumn(columnName: String, expression: TableExpression): DataFrame {
}`
I call it like this:
df.replaceColumn("my-col") { it["my-col"].map<String>{ if (it == null || it.isEmpty()) 0.0 else it.toDouble() } }