I have 2 dataframes, the first one has 53 columns and the second one has 132 column. I want to compare the 2 dataframes and remove all the columns that are not in common between the 2 dataframes and then display each dataframe containing only those columns that are common.
What I did so far is to get a list of all the column that dont't match, but I don't know how to drop them.
val diffColumns = df2.columns.toSet.diff(df1.columns.toSet).union(df1.columns.toSet.diff(df2.columns.toSet))
This is getting me a scala.collection.immutable.Set[String]. Now I'd like to use this to drop these columns from each dataframe. Something like that, but this is not working...
val newDF1 = df1.drop(diffColumns)