gpt4 book ai didi

apache-spark - 在 Pyspark 中将月份名称转换为数字

转载 作者:行者123 更新时间:2023-12-05 09:09:26 24 4
gpt4 key购买 nike

+--------+-----+---+----+----+----+----+-----+-----------+-----------+
|Currency|Month|Day|Year|Open|High| Low|Close| Volume| Market Cap|
+--------+-----+---+----+----+----+----+-----+-----------+-----------+
| tezos| Dec| 04|2019|1.29|1.32|1.25| 1.25| 46,048,752|824,588,509|
| tezos| Dec| 03|2019|1.24|1.32|1.21| 1.29| 41,462,224|853,213,342|
| tezos| Dec| 02|2019|1.25|1.26|1.20| 1.24| 27,574,097|817,872,179|
| tezos| Dec| 01|2019|1.33|1.34|1.25| 1.25| 24,127,567|828,296,390|
| tezos| Nov| 30|2019|1.31|1.37|1.31| 1.33| 28,706,667|879,181,680|
| tezos| Nov| 29|2019|1.28|1.34|1.28| 1.31| 32,270,224|867,085,098|
| tezos| Nov| 28|2019|1.26|1.35|1.22| 1.28| 44,240,281|845,073,679|
| tezos| Nov| 27|2019|1.24|1.27|1.16| 1.26| 47,723,271|829,672,736|
| tezos| Nov| 15|2019|1.22|1.26|1.15| 1.17| 32,203,363|773,992,543|
+--------+-----+---+----+----+----+----+-----+-----------+-----------+

这是我的 pyspark 数据报,如何将月份名称转换为数字???谢谢

最佳答案

使用 from_unixtime 和 unix_timestamp 函数。

示例:

df.show()
#+-----+
#|Month|
#+-----+
#| Dec|
#| Nov|
#+-----+

df.withColumn("mnth_name",from_unixtime(unix_timestamp(col("Month"),'MMM'),'MM')).show()
#+-----+---------+
#|Month|mnth_name|
#+-----+---------+
#| Dec| 12|
#| Nov| 11|
#+-----+---------+

关于apache-spark - 在 Pyspark 中将月份名称转换为数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62442352/

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