【发布时间】:2021-06-07 01:06:46
【问题描述】:
在 pyspark 中计算一个月的周数。
date id
01-01-2020 1
01-02-2020 2
01-03-2020 3
01-04-2020 4
预期的数据帧
date id no of weeks
01-01-2020 1 5
01-02-2020 2 5
01-03-2020 3 6
01-04-2020 4 5
我用下面的代码
df=df.withColumn("number_of_weeks",F.lit((calendar.monthcalendar(F.year(col('date')),F.month(col('date')))
我得到了
ValueError:无法将列转换为布尔值:请使用 '&' 表示 'and'、'|'在构建 DataFrame 布尔表达式时,for 'or', '~' for 'not'。
【问题讨论】:
标签: python apache-spark pyspark apache-spark-sql calendar