“Spark Fügen Sie die Spalte zum DataFrame hinzu” Code-Antworten

Spark Fügen Sie die Spalte zum DataFrame hinzu

from pyspark.sql.functions import lit

df = sqlContext.createDataFrame(
    [(1, "a", 23.0), (3, "B", -23.0)], ("x1", "x2", "x3"))

df_with_x4 = df.withColumn("x4", lit(0))
df_with_x4.show()
Matheus Batista

Fügen Sie die Spalte in Spark DataFrame hinzu


from pyspark.sql.functions import lit

df = sqlContext.createDataFrame(
    [(1, "a", 23.0), (3, "B", -23.0)], ("x1", "x2", "x3"))

df_with_x4 = df.withColumn("x4", lit(0))
df_with_x4.show()

## +---+---+-----+---+
## | x1| x2|   x3| x4|
## +---+---+-----+---+
## |  1|  a| 23.0|  0|
## |  3|  B|-23.0|  0|
## +---+---+-----+---+

Odd Ox

Fügen Sie die Spalte in Spark DataFrame hinzu

from pyspark.sql.functions import lit

df = sqlContext.createDataFrame(
    [(1, "a", 23.0), (3, "B", -23.0)], ("x1", "x2", "x3"))

df_with_x4 = df.withColumn("x4", lit(0))
df_with_x4.show()

## +---+---+-----+---+
## | x1| x2|   x3| x4|
## +---+---+-----+---+
## |  1|  a| 23.0|  0|
## |  3|  B|-23.0|  0|
## +---+---+-----+---+
Yellowed Yacare

Ähnliche Antworten wie “Spark Fügen Sie die Spalte zum DataFrame hinzu”

Fragen ähnlich wie “Spark Fügen Sie die Spalte zum DataFrame hinzu”

Weitere verwandte Antworten zu “Spark Fügen Sie die Spalte zum DataFrame hinzu” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen