Condividi tramite


Typeof

Restituisce una stringa di tipo DDL formattata per il tipo di dati dell'input.

Sintassi

from pyspark.sql import functions as sf

sf.typeof(col)

Parametri

Parametro TIPO Description
col pyspark.sql.Column o str Colonna di cui ottenere il tipo.

Esempi

Esempio 1: Ottenere tipi di varie colonne

from pyspark.sql import functions as sf
df = spark.createDataFrame([(True, 1, 1.0, 'xyz',)], ['a', 'b', 'c', 'd'])
df.select(sf.typeof(df.a), sf.typeof(df.b), sf.typeof('c'), sf.typeof('d')).show()
+---------+---------+---------+---------+
|typeof(a)|typeof(b)|typeof(c)|typeof(d)|
+---------+---------+---------+---------+
|  boolean|   bigint|   double|   string|
+---------+---------+---------+---------+