1from pyspark.sql.functions import lit
2
3df = sqlContext.createDataFrame(
4 [(1, "a", 23.0), (3, "B", -23.0)], ("x1", "x2", "x3"))
5
6df_with_x4 = df.withColumn("x4", lit(0))
7df_with_x4.show()
1from pyspark.sql.functions import lit
2
3df = sqlContext.createDataFrame(
4 [(1, "a", 23.0), (3, "B", -23.0)], ("x1", "x2", "x3"))
5
6df_with_x4 = df.withColumn("x4", lit(0))
7df_with_x4.show()
8
9## +---+---+-----+---+
10## | x1| x2| x3| x4|
11## +---+---+-----+---+
12## | 1| a| 23.0| 0|
13## | 3| B|-23.0| 0|
14## +---+---+-----+---+