Didier Villevalois
09/07/2022, 9:03 AMkotlinx.datetime.Instant
column timestamp
and would like to add a new column with the difference between the timestamps of the current row and the previous row. It seems I would need something similar to Panda's diff
operation but I can't find anything in Kotlin DataFrame documentation. How can I do this?Nikita Klimenko [JB]
09/07/2022, 10:39 AMval timestamp by column<Instant>()
val df = dataFrameOf(timestamp)(
Instant.fromEpochMilliseconds(1000),
Instant.fromEpochMilliseconds(3000),
Instant.fromEpochMilliseconds(5000),
Instant.fromEpochMilliseconds(3000),
)
val diff = df.add("diff") { prev()?.let { prev -> it[timestamp] - prev[timestamp] } }
It seems we missing an overload for Instant, otherwise it should have worked like this:
val timestamp by column<Int>()
val df = dataFrameOf(timestamp)(
1000,
3000,
5000,
3000,
)
val diff = df.add("diff") { diff { timestamp() } }
diff.print()
Didier Villevalois
09/07/2022, 1:41 PM