當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python pyspark months_between用法及代碼示例

本文簡要介紹 pyspark.sql.functions.months_between 的用法。

用法:

pyspark.sql.functions.months_between(date1, date2, roundOff=True)

返回日期 date1 和 date2 之間的月數。如果 date1 晚於 date2,則結果為正。如果 date1 和 date2 在一個月的同一天,或者都是一個月的最後一天,則返回一個整數(一天中的時間將被忽略)。除非將 roundOff 設置為 False ,否則結果將四舍五入為 8 位。

1.5.0 版中的新函數。

例子

>>> df = spark.createDataFrame([('1997-02-28 10:30:00', '1996-10-30')], ['date1', 'date2'])
>>> df.select(months_between(df.date1, df.date2).alias('months')).collect()
[Row(months=3.94959677)]
>>> df.select(months_between(df.date1, df.date2, False).alias('months')).collect()
[Row(months=3.9495967741935485)]

相關用法


注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 pyspark.sql.functions.months_between。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。