Created
October 16, 2024 13:58
-
-
Save SharathHebbar/8737bcca1b5312290dc1576ee6f5840b to your computer and use it in GitHub Desktop.
Revisions
-
SharathHebbar created this gist
Oct 16, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ # Read the CSV (with the first row as data) df = spark.read.format("csv").option("header", "false").load("/path/to/csvfile") # Extract the first row as the header new_header = df.first() # Create a new DataFrame without the first row df_without_first_row = df.filter(df["_c0"] != new_header["_c0"]) # Rename columns to match the values from the first row (header) new_column_names = [new_header[col] for col in df.columns] df_with_new_header = df_without_first_row.toDF(*new_column_names) df_with_new_header.show()