How to rename multiple columns in PySpark dataframe ? Last Updated : 04 Jul, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we are going to see how to rename multiple columns in PySpark Dataframe. Before starting let's create a dataframe using pyspark: Python3 # importing module import pyspark from pyspark.sql.functions import col # importing sparksession from pyspark.sql module from pyspark.sql import SparkSession # creating sparksession and giving an app name spark = SparkSession.builder.appName('sparkdf').getOrCreate() # list of students data data = [["1", "sravan", "vignan"], ["2", "ojaswi", "vvit"], ["3", "rohith", "vvit"], ["4", "sridevi", "vignan"], ["1", "sravan", "vignan"], ["5", "gnanesh", "iit"]] # specify column names columns = ['student ID', 'student NAME', 'college'] # creating a dataframe from the lists of data dataframe = spark.createDataFrame(data, columns) print("Actual data in dataframe") # show dataframe dataframe.show() Output: Method 1: Using withColumnRenamed. Here we will use withColumnRenamed() to rename the existing columns name. Syntax: withColumnRenamed( Existing_col, New_col) Parameters: Existing_col: Old column name.New_col: New column name. Example 1: Renaming single columns. Python3 dataframe.withColumnRenamed("college", "College Name").show() Output: Example 2: Renaming multiple columns. Python3 df2 = dataframe.withColumnRenamed("student ID", "Id").withColumnRenamed("college", "College_Name") df2.show() Output: Method 2: Using toDF() This function returns a new DataFrame that with new specified column names. Syntax: toDF(*col) Where, col is a new column name In this example, we will create an order list of new column names and pass it into toDF function. Python3 Data_list = ["College Id"," Name"," College"] new_df = dataframe.toDF(*Data_list) new_df.show() Output: Comment More infoAdvertise with us Next Article How to Rename Multiple PySpark DataFrame Columns K kumar_satyam Follow Improve Article Tags : Python Python-Pyspark Practice Tags : python Similar Reads How to Rename Multiple PySpark DataFrame Columns In this article, we will discuss how to rename the multiple columns in PySpark Dataframe. For this we will use withColumnRenamed() and toDF() functions. Creating Dataframe for demonstration: Python3 # importing module import pyspark # importing sparksession from pyspark.sql module from pyspark.sql i 2 min read How to Add Multiple Columns in PySpark Dataframes ? In this article, we will see different ways of adding Multiple Columns in PySpark Dataframes. Let's create a sample dataframe for demonstration: Dataset Used: Cricket_data_set_odi Python3 # import pandas to read json file import pandas as pd # importing module import pyspark # importing sparksessio 2 min read How to select and order multiple columns in Pyspark DataFrame ? In this article, we will discuss how to select and order multiple columns from a dataframe using pyspark in Python. For this, we are using sort() and orderBy() functions along with select() function. Methods UsedSelect(): This method is used to select the part of dataframe columns and return a copy 2 min read How to rename multiple column headers in a Pandas DataFrame? Here we are going to rename multiple column headers using the rename() method. The rename method is used to rename a single column as well as rename multiple columns at a time. And pass columns that contain the new values and in place = true as an argument. We pass inplace = true because we just mod 5 min read How to Rename Multiple Columns in R Renaming columns means changing the existing column names to more meaningful or consistent ones. We often do this to make our data easier to understand, follow naming rules or match analysis requirements. Methods to Rename Multiple Columns in RR programming language offers several ways to rename mul 3 min read How to rename columns in Pandas DataFrame In this article, we will see how to rename column in Pandas DataFrame. The simplest way to rename columns in a Pandas DataFrame is to use the rename() function. This method allows renaming specific columns by passing a dictionary, where keys are the old column names and values are the new column nam 4 min read Like