我尝试编写一个函数,如果满足某些条件,则从现有列中获取X坐标并将其乘以负1。该函数可以很好地编译,但是一旦将其应用于感兴趣的列,我就会不断遇到df=spark.createDataFrame([("A", "x", "3"), ("A", "y", "1"), ("B", "a", "2"), ("B", "b", "5"), ("C", "v", "2"), ("D", "f", "6")], ["id", "manager", "score"])
+---+-------+-----+
| id|manager|score|
+---+-------+-----+
| A| x| 3|
| A| y| 1|
| B| a| 2|
| B| b| 5|
| C| v| 2|
| D| f| 6|
+---+-------+-----+
df.createOrReplaceTempView("employee")
sql("select id, manager, score from (select e1.id, e1.manager, e1.score, dense_rank() over (order by e1.id) as rrank from employee e1) where rrank <= 3").show()
+---+-------+-----+
| id|manager|score|
+---+-------+-----+
| A| x| 3|
| A| y| 1|
| B| a| 2|
| B| b| 5|
| C| v| 2|
+---+-------+-----+
错误消息。
我的功能:
The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
基本上,我想编写一个接受X坐标并在满足某些条件的情况下翻转它的函数。我猜想我对布尔条件及其应用的理解还差得远,所以我们将不胜感激。
答案 0 :(得分:0)
您现在应该使用按位而不是布尔值和
,而应该使用“ and”而不是“&”实际上看起来我在这里错了。
Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
这似乎很好地回答了您的问题。