简体   繁体   English

Python-Spark-RDD日期转换

[英]Python - Spark - RDDs date convert

It's possible to convert a RDD element in datetime without transforming the RDD into DataFrame? 是否可以在日期时间转换RDD元素而无需将RDD转换为DataFrame?

I'm trying a lot of approaches but I'm not getting lucky... 我正在尝试很多方法,但是我并不幸运。

data.sortBy(lambda l: to_date(l[-2])).collect()
data.sortBy(lambda l: Date.valueOf(l[-2])).collect()
data.sortBy(lambda l: datetime(l[-2])).collect()

There exists a way to do it? 有办法吗?

Thanks! 谢谢!

sortBy can only change the order of elements in an RDD , not their contents. sortBy只能更改RDD中元素的顺序, sortBy不能更改其内容。 In order to actually get the return values of any one of your datetime conversion functions, you'll have to use map instead: 为了实际获取任何日期时间转换函数的返回值,必须使用map代替:

data.map(lambda l: datetime(l[-2])).collect()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM