【发布时间】:2017-01-18 02:34:17
【问题描述】:
我在 Scala 中有两个数据框:
df1 =
ID Field1
1 AAA
2 BBB
4 CCC
和
df2 =
PK start_date_time
1 2016-10-11 11:55:23
2 2016-10-12 12:25:00
3 2016-10-12 16:20:00
我还有一个变量start_date,其格式为yyyy-MM-dd,等于2016-10-11。
我需要根据以下条件在df1 中创建一个新列check:If PK is equal to ID AND the year, month and day of start_date_time are equal to start_date, then check is equal to 1, otherwise 0。
结果应该是这个:
df1 =
ID Field1 check
1 AAA 1
2 BBB 0
4 CCC 0
在my previous question 我有两个数据框,建议使用加入和过滤。但是,在这种情况下,它不起作用。我最初的想法是使用udf,但不确定如何使它适用于这种情况。
【问题讨论】:
-
指定您使用的是 spark。据我所知,Scala 中没有默认数据框。
标签: scala apache-spark dataframe