convert columns of pyspark data frame to lowercase

27,711

Use columns field from DataFrame

df = // load
for col in df.columns:
    df = df.withColumnRenamed(col, col.lower())

Or, as @zero323 suggested:

df.toDF(*[c.lower() for c in df.columns])
Share:
27,711
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    I have a dataframe in pyspark which has columns in uppercase like ID, COMPANY and so on

    I want to make these column names to id company and so on. Bacially convert all the columns to lowercase or uppercase depending on the requirement.

    I want to do in such away that the data types of the columns remain the same.

    How can we do that?