How to add prefix in dataframe column for all via pyspark
data = [("James","Smith","USA","CA"),("Michael","Rose","USA","NY"),("Robert","Williams","USA","CA"),("Maria","Jones","USA","FL")]
columns = ["firstname","lastname","country","state"]
df = spark.createDataFrame(data, columns)
df.show()
prefix = "P_"
for column in df.columns:
df = df.withColumnRenamed(column, prefix + column)
df.show()
Comments
Post a Comment