Need to write a DataFrame to a csv file with the file name changes according to some Iteration index (idx):
for (idx <- 1 to 3)
// do some operation and generate a df that depends on idx
...
df.coalesce(1).write.csv("/temp/path/file#.csv")
The # should vary as the idx changes (in other words, the file name should be sequentially file1.csv, file2.csv, file3.csv as the iteration goes). This seems to be a very common problem, but I have not found a clear solution yet in Scala. Thanks!