VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-rename-a-pyspark-dataframe-column-by-index/

⇱ How to rename a PySpark dataframe column by index? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to rename a PySpark dataframe column by index?

Last Updated : 23 Jul, 2025

In this article, we are going to know how to rename a PySpark Dataframe column by index using Python. we can rename columns by index using Dataframe.withColumnRenamed() and Dataframe.columns[] methods.  with the help of Dataframe.columns[] we get the name of the column on the particular index and then we replace this name with another name using the withColumnRenamed() method.

Example 1: The following program is to rename a column by its index.   

Output:

👁 Image

Example 2: The following program is to rename multiple columns by these indexes.

Output:

👁 Image

Comment