Pyspark – 具有时间条件的列

huangapple go评论66阅读模式
英文:

Pyspark - a column with time condition

问题

我想要的是一旦时间大于07:00:00,列'tatsaechlicher_einsatztag'的日期应为'einsatzdatum' + 1,如果时间小于07:00:00,则应为同一天。问题在于代码无法读取第121行的字符串。目前,始终会添加一天,因为它无法识别字符串。

英文:

I want that once the time is greater than 07:00:00, the date of the column 'tatsaechlicher_einsatztag' should be 'einsatzdatum' + 1, and if the time is less than 07:00:00, then it should be the same day. The problem here is that the code cannot read the string in line 121. Currently, one day is always added because it does not recognize the string.
Pyspark – 具有时间条件的列

答案1

得分: 1

你可以通过使用'hours'函数来实现这个。你需要从pyspark.sql中导入它,例如:

from pyspark.sql import functions as F

要执行比较,可以这样做:

F.hours(F.col("column_name")) < F.lit(7)
英文:

You can do this by using the 'hours' function. You'll need to import this from pyspark.sql e.g.

from pyspark.sql import functions as F

To actually perform the comparison it would be something like this.

F.hours(F.col(&quot;column_name&quot;)) &lt; F.lit(7)

huangapple
  • 本文由 发表于 2023年5月14日 20:14:30
  • 转载请务必保留本文链接:https://go.coder-hub.com/76247425.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定