作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个要求,需要满足以下请求:
IF EndOfMonth(to_date(df.col1, 'DD.MM.YYYY')) >= EOM(CURRENT_DATE):
THEN "OldCustomer"
ELSE "NewCustomer"
输入数据框:
col1 (stringtype)
20190523
20200428
20130819
Current_date:从 python import datetime 获取
from datetime import date
now = date.today()
输出应该是这样的:
col1 (Stringtype) col1_formated customer(stringtype)
20190523 23.05.2019 oldcustomer
20200428 28.04.2020 newcustomer
20130819 19.03.2013 oldcustomer
请帮忙进行eom格式编码?这真的很有帮助。
最佳答案
last_day
函数就是您正在寻找的:
df.withColumn("col1_formated", date_format(to_date("col1", "yyyyMMdd"), "dd.MM.yyyy")) \
.withColumn("customer",
when(last_day(to_date("col1", "yyyyMMdd")) >= last_day(current_date()),
"OldCustomer").otherwise("NewCustomer")
).show()
关于python - 使用 pySpark 计算月末差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59518792/
我很难将我的数据按月分组。我什至以编程方式过滤我的数据以仅返回当月的最后一天并计算月值。我试图找到关于“dataGrouping”属性的一个很好的解释,但没有运气理解它也没有正确实现它。每个结果都以每
我有一个问题,从一天中获取月底的最快方法是什么。我有一个非常大的表,我希望我的代码能够快速运行。我当前的代码如下所示: library(lubridate) end_of_month % as.Dat
我是一名优秀的程序员,十分优秀!