Если вы еще не знаете ожидаемые категориальные значения, вы можете использовать pyspark.sql.functions.udf
для разделения и тегов в массив значений и функцию pyspark.sql.functions.explode
для преобразования их в столбцы.Затем вы можете повернуть значения в столбцы:
# required imports
import pyspark.sql.functions as F
from pyspark.sql.types import ArrayType, StringType
import re
# regex pattern to split 'tagged values'
pat = re.compile('<(.*?)>')
#udf to split string to array of values
split_f = f.udf(lambda s: pat.split(s), ArrayType(StringType()))
# sample data
df = spark.createDataFrame([(0,'<a><b>','ex1'),(1,'<a><c>','ex2')], ['Id', '---Tags---', 'some_text'])
+---+----------+---------+
| Id|---Tags---|some_text|
+---+----------+---------+
| 0| <a><b>| ex1|
| 1| <a><c>| ex2|
+---+----------+---------+
df.withColumn('exploded',
F.explode(split_f(F.col('---Tags---'))))
.groupby('Id').pivot('exploded').count().na.fill(0).show()
+---+---+---+---+
| Id| a| b| c|
+---+---+---+---+
| 0| 1| 1| 0|
| 1| 1| 0| 1|
+---+---+---+---+