我正在使用 Pyspark 和 Python 2.7。我在字符串中有一个日期列(带毫秒)并且想转换为时间戳
这是我到目前为止所尝试过的
df = df.withColumn('end_time', from_unixtime(unix_timestamp(df.end_time, '%Y-%M-%d %H:%m:%S.%f')) )
printSchema()
shows
end_time: string (nullable = true)
当我将时间戳记作为变量的类型时
尝试使用from_utc_timestamp http://spark.apache.org/docs/2.1.0/api/python/pyspark.sql.html#pyspark.sql.functions.from_utc_timestamp:
from pyspark.sql.functions import from_utc_timestamp
df = df.withColumn('end_time', from_utc_timestamp(df.end_time, 'PST'))
您需要为该函数指定时区,在本例中我选择PST
如果这不起作用,请给我们一个显示几行的示例df.end_time
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)