[英]How can I convert dictionary entries from String to timestamp in pyspark?
I have a dictionary with two dates:我有一本有两个日期的字典:
dateFilter = {"date1": "2021-05-14", "date2": "2021-05-10"}
In my dataframe I have two columns of type timestamp:在我的 dataframe 中,我有两列时间戳类型:
|date1 | date2|
———————————————
|timea | timeb|
|timec | timed|
I want to filter this table based on whether the entries are smaller than the time in the dictionary我想根据条目是否小于字典中的时间来过滤这个表
Table = Table.filter(F.col(column) <= DateFilters[date1])
The column needs to stay type timestamp so in order to compare I would like to convert the dictionary entries from String to Timestamp.该列需要保持类型时间戳,所以为了比较我想将字典条目从字符串转换为时间戳。 I've tried this:
我试过这个:
DateFilters[date1] = DateFilters[date1].cast(T.TimestampType)
But this doesn't work.但这不起作用。
You can create a literal timestamp column from the dictionary value:您可以从字典值创建文字时间戳列:
import pyspark.sql.functions as F
Table = Table.filter(F.col(column) <= F.lit(DateFilters["date1"]).cast('timestamp'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.