I have 10 data frames pyspark.sql.dataframe.DataFrame, obtained from randomSplit as (td1, td2, td3, td4, td5, td6, td7, td8, td9, td10) = td.randomSplit([.1, .1, .1, .1, .1, .1, .1, .1, .1, .1], seed = 100) Now I want to join 9 td's into a single data frame, how should I do that?I have already tried with unionAll, but this function accepts only two arguments. td1_2 = td1.unionAll(td2) # this is working finetd1_2_3 = td1.unionAll(td2, td3) # error TypeError: unionAll() takes exactly 2 arguments (3 given)Is there any way to combine more than two data frames row-wise? The purpose of doing this is that I am doing 10-fold Cross Validation manually without using PySpark CrossValidator method, So taking 9 into training and 1 into test data and then I will repeat it for other combinations. 
Merging multiple data frames row-wise in PySpark
python;apache spark;cross validation;pyspark
Stolen from: https://stackoverflow.com/questions/33743978/spark-union-of-multiple-rddsOutside of chaining unions this is the only way to do it for DataFrames.from functools import reduce  # For Python 3.xfrom pyspark.sql import DataFramedef unionAll(*dfs):    return reduce(DataFrame.unionAll, dfs)unionAll(td2, td3, td4, td5, td6, td7, td8, td9, td10)What happens is that it takes all the objects that you passed as parameters and reduces them using unionAll (this reduce is from Python, not the Spark reduce although they work similarly) which eventually reduces it to one DataFrame.If instead of DataFrames they are normal RDDs you can pass a list of them to the union function of your SparkContextEDIT: For your purpose I propose a different method, since you would have to repeat this whole union 10 times for your different folds for crossvalidation, I would add labels for which fold a row belongs to and just filter your DataFrame for every fold based on the label