是否可以使用火花数据框(pyspark)中的 d-type 找到哪一列是日期? [英] Is it possible to find which column is date using d-type from spark data frame (pyspark)?

查看:48
本文介绍了是否可以使用火花数据框(pyspark)中的 d-type 找到哪一列是日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框:-

df =
   Name   Date_1     Date_2     Roll.no
   kiram  22-01-2020 23-01-2020  20
   krish  24-02-2020 05-01-2020  25
   verm   09-01-2020 25-02-2020  24
   kirn   14-12-2019 25-01-2021  56

现在我想使用 d-types. 查找日期列.正如我们所知,在 pyspark 中日期被视为 strings,我们如何描述日期列 d-type 为 date 类型而不是 string?这是因为我只想在日期列上应用一些函数.有什么办法可以找出哪一列属于 d-type 'Date'?

Now I want to find the date column using d-types. As we know that in pyspark date are treated as strings, how do we describe the date column d-type as date type but not string? This is because I want to apply some function only on date columns. Is there any way to find which column falls into d-type 'Date'?

推荐答案

尝试

df.printSchema()

应该说是时间戳还是日期

it should say if its a timestamp or date

或者您可以使用 to_date() 转换为日期格式

or you can use to_date() to convert to date format

to_date("date").alias("date")

这篇关于是否可以使用火花数据框(pyspark)中的 d-type 找到哪一列是日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆