AssertionError:col应该是Column [英] AssertionError: col should be Column
本文介绍了AssertionError:col应该是Column的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在PySpark中创建新列,并用今天的日期填充该列?
How to create a new column in PySpark and fill this column with the date of today?
这是我尝试过的:
import datetime
now = datetime.datetime.now()
df = df.withColumn("date", str(now)[:10])
我收到此错误:
AssertionError:col应该是Column
AssertionError: col should be Column
推荐答案
如何在PySpark中创建一个新列,并用今天的日期填充该列?
How to create a new column in PySpark and fill this column with the date of today?
已有功能:
from pyspark.sql.functions import current_date
df.withColumn("date", current_date().cast("string"))
AssertionError:col应该是Column
AssertionError: col should be Column
使用文字
from pyspark.sql.functions import lit
df.withColumn("date", lit(str(now)[:10]))
这篇关于AssertionError:col应该是Column的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文