【问题标题】:How to convert string to date in AWS Glue如何在 AWS Glue 中将字符串转换为日期
【发布时间】:2020-03-26 11:34:47
【问题描述】:

我在 AWS S3 中有一个 csv 文件,当我执行爬虫时,日期为 01/01/2016 04.21 的字段在 AWS 胶水中被视为字符串。

如何将其更改为日期类型?

我尝试使用 AWS Glue 中的“修改架构”按钮,但它最终有一个空白字段。

【问题讨论】:

  • 修改后的架构中日期列的格式是什么

标签: pyspark etl aws-glue amazon-athena


【解决方案1】:

将动态帧转换为 Pyspark 数据帧并将 Pyspark 用于所有内容。更简单:

from pyspark.sql.functions import from_unixtime, unix_timestamp, col

df= dyf.toDF()
df = df.withColumn(col(columnname), from_unixtime(unix_timestamp(col(columnname),"dd/MM/yyyy hh.mm")))

【讨论】:

    猜你喜欢
    • 2021-05-14
    • 1970-01-01
    • 1970-01-01
    • 2020-05-24
    • 1970-01-01
    • 2018-04-15
    • 2017-06-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多