【发布时间】:2018-12-14 22:24:39
【问题描述】:
我使用的是 spark 2.0.1,
df.show()
+--------+------+---+-----+-----+----+
|Survived|Pclass|Sex|SibSp|Parch|Fare|
+--------+------+---+-----+-----+----+
| 0.0| 3.0|1.0| 1.0| 0.0| 7.3|
| 1.0| 1.0|0.0| 1.0| 0.0|71.3|
| 1.0| 3.0|0.0| 0.0| 0.0| 7.9|
| 1.0| 1.0|0.0| 1.0| 0.0|53.1|
| 0.0| 3.0|1.0| 0.0| 0.0| 8.1|
| 0.0| 3.0|1.0| 0.0| 0.0| 8.5|
| 0.0| 1.0|1.0| 0.0| 0.0|51.9|
我有一个数据框,我想使用 withColumn 向 df 添加一个新列,并且新列的值基于其他列值。我用过这样的东西:
>>> dfnew = df.withColumn('AddCol' , when(df.Pclass.contains('3.0'),'three').otherwise('notthree'))
报错
TypeError: 'Column' object is not callable
可以帮助解决这个错误。
【问题讨论】:
标签: python apache-spark pyspark apache-spark-sql