使用 python 将空列添加到 Spark 中的数据框
Add empty column to dataframe in Spark with python
我有一个数据框,我想用另一个数据框制作一个 unionAll。问题是第二个数据框比第一个多了三列。有没有办法在我的第一个数据框中添加只有空单元格的三列?
使用 withColumn
spark-dataframe 对象
DF.withColumn("NewCol","Value")
df.withColumn('NewColumn', lit(None).cast(StringType()))
也许这会有所帮助
要添加字符串类型列:
from pyspark.sql.types import StringType
df.withColumn("COL_NAME", lit(None).cast(StringType()))
添加整数类型
from pyspark.sql.types import IntegerType
df.withColumn("COL_NAME", lit(0).cast(IntegerType()))
我有一个数据框,我想用另一个数据框制作一个 unionAll。问题是第二个数据框比第一个多了三列。有没有办法在我的第一个数据框中添加只有空单元格的三列?
使用 withColumn
spark-dataframe 对象
DF.withColumn("NewCol","Value")
df.withColumn('NewColumn', lit(None).cast(StringType()))
也许这会有所帮助
要添加字符串类型列:
from pyspark.sql.types import StringType
df.withColumn("COL_NAME", lit(None).cast(StringType()))
添加整数类型
from pyspark.sql.types import IntegerType
df.withColumn("COL_NAME", lit(0).cast(IntegerType()))