0

I have an array of data frames called "dataFrames" and looks like this:

dataFrames(0)
+----------+--------------------+---------+-------------+
|Periodo   |              frutas|freq     |prods_qty    |
+----------+--------------------+---------+-------------+
|         1|Apple, Watermelon   |        1|            2|
|         1|Banana, StrawBerry  |        2|            2|
+----------+--------------------+---------+-------------+

dataFrames(1)
+----------+--------------------+---------+-------------+
|Periodo   |              frutas|freq     |prods_qty    |
+----------+--------------------+---------+-------------+
|         2|Naranjas, Fresas    |        7|            2|
|         2|Pineapple, Apples   |        9|            2|
+----------+--------------------+---------+-------------+

Well, I need to get a single dataframe like this:

+----------+--------------------+---------+-------------+
|Periodo   |              frutas|freq     |prods_qty    |
+----------+--------------------+---------+-------------+
|         1|Apple, Watermelon   |        1|            2|
|         1|Banana, StrawBerry  |        2|            2|
|         2|Naranjas, Fresas    |        7|            2|
|         2|Pineapple, Apples   |        9|            2|
+----------+--------------------+---------+-------------+

For this example the length of the array is 1, but the array could any size.

It is possible to achive this... or i need to store the dataframes into a hive table?

Thanks in advance

LeeFernan
  • 5
  • 4

1 Answers1

0

You can reduce a sequence or array of DataFrames together using unionAll:

val dfs = Array(df1, df2, df3)

val all = dfs.reduce(_ unionAll _)
DNA
  • 42,007
  • 12
  • 107
  • 146