from pyspark.ml.feature import OneHotEncoder,StringIndexer encodeer = OneHotEncoder(inputCol="City_Index",outputCol="City_Vec") encodeer_df = encodeer.fit(indexed).transform(indexed) encodeer_df["City_Index","City_Vec"].show(5)