本文簡要介紹
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)]
相關用法
- Python pyspark months用法及代碼示例
- Python pyspark month用法及代碼示例
- Python pyspark monotonically_increasing_id用法及代碼示例
- Python pyspark map_from_arrays用法及代碼示例
- Python pyspark map_filter用法及代碼示例
- Python pyspark md5用法及代碼示例
- Python pyspark melt用法及代碼示例
- Python pyspark map_from_entries用法及代碼示例
- Python pyspark merge用法及代碼示例
- Python pyspark map_zip_with用法及代碼示例
- Python pyspark map_values用法及代碼示例
- Python pyspark map_entries用法及代碼示例
- Python pyspark map_concat用法及代碼示例
- Python pyspark map_keys用法及代碼示例
- Python pyspark minute用法及代碼示例
- Python pyspark create_map用法及代碼示例
- Python pyspark date_add用法及代碼示例
- Python pyspark DataFrame.to_latex用法及代碼示例
- Python pyspark DataStreamReader.schema用法及代碼示例
- Python pyspark MultiIndex.size用法及代碼示例
- Python pyspark arrays_overlap用法及代碼示例
- Python pyspark Series.asof用法及代碼示例
- Python pyspark DataFrame.align用法及代碼示例
- Python pyspark Index.is_monotonic_decreasing用法及代碼示例
- Python pyspark IsotonicRegression用法及代碼示例
注:本文由純淨天空篩選整理自spark.apache.org大神的英文原創作品 pyspark.sql.functions.months_between。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。