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])
Author by
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
I have a dataframe in pyspark which has columns in uppercase like
ID
,COMPANY
and so onI 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?