Pyspark from_unixtime(unix_timestamp)不会转换为时间戳 [英] Pyspark from_unixtime (unix_timestamp) does not convert to timestamp
本文介绍了Pyspark from_unixtime(unix_timestamp)不会转换为时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将Pyspark与Python 2.7一起使用。我在字符串中有一个日期列(带有ms),并且想要转换为时间戳记
I am using Pyspark with Python 2.7. I have a date column in string (with ms) and would like to convert to timestamp
这是我到目前为止已经尝试过的操作
This is what I have tried so far
df = df.withColumn('end_time', from_unixtime(unix_timestamp(df.end_time, '%Y-%M-%d %H:%m:%S.%f')) )
printSchema()
显示
end_time:字符串(nullable = true)
我将时间戳记用作变量的类型
when I expended timestamp as the type of variable
推荐答案
尝试使用 from_utc_timestamp
:
from pyspark.sql.functions import from_utc_timestamp
df = df.withColumn('end_time', from_utc_timestamp(df.end_time, 'PST'))
您需要指定一个时区函数,在这种情况下,我选择了 PST
You'd need to specify a timezone for the function, in this case I chose PST
如果这不起作用,请举几个例子显示 df.end_time
If this does not work please give us an example of a few rows showing df.end_time
这篇关于Pyspark from_unixtime(unix_timestamp)不会转换为时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文