在PySpark中将Unix时间戳减法转换为小时/分钟

时间:2019-07-30 13:52:45

标签: pyspark pyspark-sql

我正在两个unix时间戳之间执行LAG操作,它工作得很好。但是,我想将结果列转换为小时/分钟

df_new = df_new.withColumn("diff", F.when(F.isnull(df_new.calculated_time - df_new.prev_value), 0)
                              .otherwise(df_new.calculated_time.cast('long') - df_new.prev_value.cast('long')))

输出-

+--------------------+--------------------+---------------+-------------+---------+
|         primary_key|              status|calculated_time|   prev_value|     diff|
+--------------------+--------------------+---------------+-------------+---------+
|{"approval_id": "...|Pending review by...|  1562315397258|         null|        0|
|{"approval_id": "...|              Denied|  1562936139570|1562315397258|620742312|
|{"approval_id": "...|Request clarifica...|  1563172343614|1562936139570|236204044|
|{"approval_id": "...|                null|  1563172473488|1563172343614|   129874|
|{"approval_id": "...|            Approved|  1563190166533|1563172473488| 17693045|
+--------------------+--------------------+---------------+-------------+---------+

在“差异”列中,我想有分钟。谁能帮忙吗?

0 个答案:

没有答案