Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]
Hi I have a dataframe (loaded CSV) where the inferredSchema filled the column names from the file. I am trying to get rid of white spaces from column names - because otherwise the DF cannot be saved as parquet file - and did not find any usefull method for renaming.
The method withColumnRenamed("Company ID","Company_ID") works, but I need to repeat it for every column in the dataframe. I tried to to use toDF method,
such as:
val dfnew = df.toDF( df.columns.map( a => a.replace(" ","_") ) );
but it failed.,
Any ideas?
Created 01-15-2016 07:00 AM
I have found a solution to this:
df.registerTempTable("tmp");
val newdf = sqlContext.sql(""" select 'Company ID' as Company_ID, 'Product ID' as Product_ID, .. from tmp""");
newdf.saveAsParquetFile(...);
T.
Created 01-15-2016 07:00 AM
I have found a solution to this:
df.registerTempTable("tmp");
val newdf = sqlContext.sql(""" select 'Company ID' as Company_ID, 'Product ID' as Product_ID, .. from tmp""");
newdf.saveAsParquetFile(...);
T.
Created 01-15-2016 07:19 AM