-
Notifications
You must be signed in to change notification settings - Fork 50
Support replaceNA? #118
Comments
Related to #110 |
Thanks for the suggestion. Indeed I find the current approach clumsy as well. I was thinking about
But maybe that's too much as well, and a per column extension would be the most intuitive solution. For sure a PR would be great here. I'm happy to help as well, but would value your input first regarding an intuitive API design. |
You are right. Calling I think at least there are two problems here:
fun DataFrame.replaceColumn(columnName: String, update: (DataCol) -> DataCol) {
val df = this
df.addColumn(columnName) {
update(it[columnName])
}
}
// would need some help to make this work:
fun DataCol.replaceNA(defaultValue: Any): DataCol = values().map { it?: defaultValue}
sales.replaceColumn("product") {
it.replaceNA("AAA")
}.replaceColumn("sales") {
it.replaceNA(0)
} Another kind of API may be like the following. But it seems a bit harder to set up, as I think we would need some kind of mutable column to collect all the mutations: sales.replaceColumns("product", "sales") { productColumn, salesColumn ->
productColumn.replaceNA("AAA")
salesColumn.replaceNA(0)
} This is to mimic the style of buildList API or buildString which take a function to mutate How do you think about these two APIs? |
Sorry for the delay & and thanks for the proposal. Rearding 1. It's not that simple to replace listOf with varargs, because there are multiple implementations of krangl/src/main/kotlin/krangl/Select.kt Line 52 in 17be47a
Regarding 2. I don't think that we can express With some weeks since my last comment, I actually like the idea of |
I've found it a bit counter-intuitive to replace NA with the value I want, as there's no API to call directly.
For now, I've used the below logic to do the job. May I know is this the proper way to do so? Do we need to add such API to krangl? (I'm happy to raise a PR if the below snippet is the officital way)
The text was updated successfully, but these errors were encountered: