from pyspark.ml.feature import StringIndexer
stringIndexer = StringIndexer(inputCol="label", outputCol="indexed")
model = stringIndexer.fit(data) indexedData = model.transform(data)
outputCol = stringIndexer.getOutputCol()Brief Explanation: The above code examples use the StringIndexer transformer in PySpark to encode a categorical variable. In the first step, we import the required package. Then, we initialize the StringIndexer with an input column "label" and set the output column to "indexed". Next, we fit the StringIndexer to our data and transform it. Finally, we retrieve the output column name using the getOutputCol() method. Package Library: The PySpark.ml.feature package is used in the code examples.