我有一个数据框df,我想把其中一些列转换为类别类型。使用pandas,我可以按照以下方式完成:
for col in categorical_collist:
df[col] = df[col].astype('category')
我想在Pyspark中进行列转换。我该怎么做?
我尝试在Pyspark中使用以下代码。但在操作期间,它没有给出我预期的输出。
from pyspark.sql.types import StringType
for col in categorical_collist:
df = df.withColumn(col, df[col].cast(StringType()))