gpt4 book ai didi

python - 在 AWS Glue/pyspark 中将纪元转换为日期时间

转载 作者:太空宇宙 更新时间:2023-11-03 14:34:08 26 4
gpt4 key购买 nike

我正在使用 pyspark 在 AWS Glue 中处理一个数据帧,我的 df 中的一条消息如下所示:

{  
"version":"0.0.1",
"device_id":"df4c13ddddb1bb8fea9fe762",
"session_id":"721cf47cf8408b30bc57743717",
"session_start":1508450739332,
"source_id":"5",
"body":{
"message_id":"2e6d83c677a7b4f3683366d",
"message_type":1,
"message_time":1508450739332,
"url":"http://sample_url/"
},
"partition_0":"2017",
"partition_1":"10",
"partition_2":"19",
"partition_3":"22"
}

我正在尝试将 body.message_time (纪元以毫秒为单位)转换为日期时间字段。我尝试了 from_unixtime 函数:

unnested_df.withColumn("messages_datetime", from_unixtime(unnested_df.body.message_time.divide(1000)).show()

给我这个错误:

TypeError: 'Column' object is not callable

我只是将该列传递到 from_unixtime 函数中。知道如何解决这个问题吗?

谢谢

最佳答案

您会收到异常,因为 Column 没有 divide 方法。使用 / 运算符:

unnested_df.withColumn("messages_datetime", from_unixtime(unnested_df.body.message_time / 1000)

关于python - 在 AWS Glue/pyspark 中将纪元转换为日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47083219/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com