Given a @DataSchema
how do I go about creating an empty DataFrame<MySchema>
and then adding rows?
I tried val df = emptyDataFrame<MySchema>()
but df.append(...)
results in an exception (division by zero) since the empty df
has zero columns.
The documentation for emptyDataFrame<T>()
says:
Returns [DataFrame] with no rows and no columns.
To create [DataFrame] with empty columns or empty rows see [DataFrame.empty]
Essentially, this function creates a completely empty data frame which is just cast to your type. This explains why you cannot append values to it.
I think what you're looking for instead is the function DataFrame.emptyOf<T>()
, whose docs says:
Creates a DataFrame with empty columns (rows = 0).
Can be used as a "null object" in aggregation operations, operations that work on columns (select, reorder, ...)
I created an issue on Github for these functions to be clarified/improved, because I understand the confusion they can cause.