2017-12-20 54 views
0

PySparkで新しいカラムを作成し、このカラムに今日の日付を記入する方法は?AssertionError:colはカラムであるべきです

これは私が試したものです:

import datetime 
now = datetime.datetime.now() 
df = df.withColumn("date", str(now)[:10]) 

私はこのエラーを取得する:

AssertionError: col should be Column

答えて

2

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 should be Column

リテラルを使用

from pyspark.sql.functions import lit 

df.withColumn("date", lit(str(now)[:10])) 
関連する問題