Jason5lee
01/04/2024, 1:12 PMzaleslaw
01/04/2024, 3:46 PMJason5lee
01/05/2024, 12:17 AMaltavir
01/05/2024, 7:13 AMchrmelchior
01/05/2024, 7:24 AMdata class Test(val foo: String, val bar: Int)
val df = DataFrame.emptyOf<Test>()
df
See also https://stackoverflow.com/questions/77215912/adding-rows-to-an-empty-typed-dataframe/77244204#77244204Jason5lee
01/05/2024, 7:29 AMJason5lee
01/05/2024, 9:17 AMinline fun getData(eachRow: (Int, String, /* column values */) => Unit)
. This function retrieves the data and applies eachRow
to every row. How can I best use this to construct a data frame?
The ChatGPT answers to build a list first then convert to dataframe. Is it the best approach?altavir
01/05/2024, 9:22 AMaltavir
01/05/2024, 9:24 AMaltavir
01/05/2024, 9:25 AMchrmelchior
01/05/2024, 9:50 AM%use dataframe
data class Test(val foo: String, val bar: Int)
var df = DataFrame.emptyOf<Test>()
repeat (10) { no ->
df = df.append("Hello $no", no)
}
df
But given that the DataFrame API is functional, you end up constructing quite a lot of intermediate DataFrame objects which is copying all the data from the previous one, so if performance is a concern it will probably be faster to collect all your rows an a List and add them all in one go.Jolan Rensen [JB]
01/05/2024, 10:50 AM@DataSchema
) representing a row and use the buildList {}
function from the standard library to build a list of instances of your data class from your read function. Next use .toDataFrame()
to convert the list to a DataFrame 🙂
See the docs for more information, hope that helps!