Я создал Dataframe из таблицы Hive и хочу получить имена полей / столбцов.
>>>a=df.schema >>>a StructType(List(StructField(empid, IntegerType, true), StructField(empname,StringType, true)))
Как получить имена полей (empid, empname) из этого объекта.
Использование pyspark.sql.types.StructType.fieldnames:
pyspark.sql.types.StructType.fieldnames
fieldNames() Возвращает все имена полей в списке. >>> struct = StructType([StructField("f1", StringType(), True)]) >>> struct.fieldNames() ['f1']
fieldNames()
Возвращает все имена полей в списке.
>>> struct = StructType([StructField("f1", StringType(), True)]) >>> struct.fieldNames() ['f1']