python – AssertionError:col应该是Column
发布时间:2020-12-15 15:39:43 所属栏目:Python 来源:互联网
导读:如何在PySpark中创建一个新列并使用今天的日期填充此列? 这是我试过的: import datetimenow = datetime.datetime.now()df = df.withColumn(date, str(now)[:10]) 我收到此错误: AssertionError: col should be Column How to create a new column i
如何在PySpark中创建一个新列并使用今天的日期填充此列? 这是我试过的: import datetime now = datetime.datetime.now() df = df.withColumn("date",str(now)[:10]) 我收到此错误:
解决方法
已有功能: from pyspark.sql.functions import current_date df.withColumn("date",current_date().cast("string"))
使用文字 from pyspark.sql.functions import lit df.withColumn("date",lit(str(now)[:10])) (编辑:百色站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- python – Django:使用对象作为字典键是否合理?
- python – Tkinter Canvas将项目移动到顶层
- python – TypeError:尝试模拟classmethod时的未绑定方法
- python – Sublime Text 3 API:从文件获取所有文本
- python – 函数参数中的列表理解
- python – 如何在`scipy.integrate.dblquad`中增加函数的细
- Pythonic计算pandas数据帧条纹的方法
- 在远程服务器上使用ein(emacs ipython notebook)
- Python:如何找到使用matplotlib绘制的图形的斜率?
- 有GIL时,你可以在Python中竞争条件吗?