我在mac上的anaconda spyder中使用3.6 Python版本.但我想将其更改为Python 2.7.
谁能告诉我怎么做?
我正在使用火花 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|
Run Code Online (Sandbox Code Playgroud)
我有一个数据框,我想使用 withColumn 向 df 添加一个新列,新列的值基于其他列值。我使用了这样的东西:
>>> dfnew = df.withColumn('AddCol' , when(df.Pclass.contains('3.0'),'three').otherwise('notthree'))
Run Code Online (Sandbox Code Playgroud)
它给出了一个错误
TypeError: 'Column' object is not callable
Run Code Online (Sandbox Code Playgroud)
可以帮助如何克服这个错误。