andyg
02/13/2024, 11:27 AMPavel Gorgulov
02/13/2024, 12:28 PMJolan Rensen [JB]
02/13/2024, 1:01 PMJolan Rensen [JB]
02/13/2024, 1:11 PMfilter { it.someCol != null}
with dropNulls { someCol }
as that's a bit easier to read
• A lot of !!
can be replaced with .castToNotNullable()
on the column in the previous operation
For example, n.o. 49:
dfPenguins
.dropNulls { body_mass_g }
.convert { body_mass_g.castToNotNullable() }.with {
when {
it < 3500 -> "small"
it < 5000 -> "medium"
// ... especially useful when there are lots of cases
// a map also works, as we demonstrated in #41
else -> "large"
}
}
...
Of course your version is equally correct 🙂 it's just my tasteJolan Rensen [JB]
02/13/2024, 1:35 PMdf.parse { jsonStringCol }
(or alternatively df.convert { jsonStringCol }.with { DataRow.readJsonStr(it) }
) and then the json-reading abilities of DF will be utilized.
Of course, Kotlinx Serialization is also possible, but sometimes that's a bit much boilerplate IMO.
Plus, it allows you to show column groups, which SQL doesn't support 🙂 (right?)andyg
02/13/2024, 8:04 PMdropNulls
in some places but I agree it is clearer... I've replaced most null filters with it, and `castToNotNullable`where appropriate. Also added some json parse
examples, thank you for that tip, definitely is a nice option rather than all the setup necessary for a full de-serialization.andyg
02/13/2024, 8:07 PM