How do I append to a list when using foreach on a dataframe? For my case, I would like to collect values from each row using a self defined function and append them into a list. The function would return a list of values.
Here is the pseudocode below. I would like to try something like this:
listOfDfs = []
df.foreach(lambda row: listOfDfs.extend(getRowInfo(row)))
listOfDfs
But listOfDfs remain empty. I am guessing this is because foreach returns empty. I've tried using map
and also doesn't seem to append listOfDfs
. Can anyone help me with this?