У меня есть входные данные, как показано ниже -
Customer_ID,General,General
Channel,Nominal,Character
WeekDateSunday,Discrete,Numeric
RevenueWeekN01,Continuous,Numeric
RevenueWeekN02,Continuous,Numeric
RevenueWeekN03,Continuous,Numeric
RevenueWeekN04,Continuous,Numeric
RevenueWeekN05,Continuous,Numeric
RevenueWeekN06,Continuous,Numeric
RevenueWeekN07,Continuous,Numeric
RevenueWeekN08,Continuous,Numeric
Мне нужны выходные данные, как показано ниже, просто с добавлением одного столбца (этот столбец представляет собой structField на основе столбца 3):
Customer_ID,General,General, StructFieldType
Channel,Nominal,Character, StructField(Channel,StringType(), True)
WeekDateSunday,Discrete,Numeric, StructField(WeekDateSunday,DoubleType(), True)
RevenueWeekN01,Continuous,Numeric, StructField(RevenueWeekN01,DoubleType(), True)
RevenueWeekN02,Continuous,Numeric, StructField(RevenueWeekN02,DoubleType(), True)
RevenueWeekN03,Continuous,Numeric, StructField(RevenueWeekN03,DoubleType(), True)
RevenueWeekN04,Continuous,Numeric, StructField(RevenueWeekN04,DoubleType(), True)
RevenueWeekN05,Continuous,Numeric, StructField(RevenueWeekN05,DoubleType(), True)
RevenueWeekN06,Continuous,Numeric, StructField(RevenueWeekN06,DoubleType(), True)
RevenueWeekN07,Continuous,Numeric StructField(RevenueWeekN06,DoubleType(), True)
RevenueWeekN08,Continuous,Numeric StructField(RevenueWeekN06,DoubleType(), True)
Ниже приведен код, который я использовал, это правильно?
data_type.withColumn('structformat',when(col("Description") == 'Numeric', StructField(col("Field_Name"),DoubleType(), True)).otherwise(StructField(col("Field_Name"),StringType(), True)).show()
Выдает ниже ошибки при выполнении-
AssertionError: field name should be string