0

I'm trying to create new dataframes using the columns of an initial dataframe (df0).

I tried to create an array of strings to use it for dataset names, but it didn't work.

String [] column = ds.columns();
String [] dsName = new String[10];
int max=ds.schema().length();
for (i=0; i<max; i++) {
        Dataset<Row> dsName[i]=null;
        for (j=0; j<max && j!=i; j++) {
            for (k=0; k<max && k!=i && k!=i; k++) {
                            dsName[i]= ds.select(ds.col(column[i]),
                                                ds.col(column[j]),
                                                ds.col(column[k]));

                       }
               }
}

Expected result for (initial df0, and 3 dfs df1i):

df11 = df0.select(df0.col("1"),df0.col("2"));
df12 = df0.select(df0.col("1"),df0.col("3"));
df13 = df0.select(df0.col("1"),df0.col("4"));
jgp
  • 2,069
  • 1
  • 21
  • 40
Aziz Azizos
  • 15
  • 1
  • 6
  • 1
    Possible duplicate of [Assigning variables with dynamic names in Java](https://stackoverflow.com/questions/6729605/assigning-variables-with-dynamic-names-in-java) – 10465355 Feb 12 '19 at 23:44
  • It's easy to do for arrays, lists .. But I don't see how to use the samething for dataframes. We cannot create an array of dataframes. – Aziz Azizos Feb 12 '19 at 23:54
  • 1
    What is your ultime goal? This seems a little cumbersome. I never used an array of dataframes (I used maps in some occasion). Not saying you’re wrong, but maybe you can provide a little more... – jgp Feb 13 '19 at 07:09
  • Let's say we have a dataframe with 10 columns, the goal is to create multiple dataframes from each 3 columns in the initial dataframe. – Aziz Azizos Feb 13 '19 at 11:29

0 Answers0