【发布时间】:2019-02-24 06:12:18
【问题描述】:
假设我有一个名为“orderitems”的数据框,其架构如下
DataFrame[order_item_id: int, order_item_order_id: int, order_item_product_id: int, order_item_quantity: int, order_item_subtotal: float, order_item_product_price: float]
所以作为检查数据质量的一部分,我需要确保所有行都满足公式:order_item_subtotal = (order_item_quantity*order_item_product_price)。 为此,我需要添加一个名为“valid”的单独列,对于所有满足上述公式的行,它应该具有“Y”作为值,对于所有其他行,它应该具有“N”作为值。 我决定使用 when() 和 else() 以及 withColumn() 方法,如下所示。
orderitems.withColumn("valid",when(orderitems.order_item_subtotal != (orderitems.order_item_product_price * orderitems.order_item_quantity),'N').otherwise("Y"))
但它在错误下方返回我:
TypeError: 'Column' object is not callable
我知道发生这种情况是因为我试图将两个列对象相乘。但我不知道如何解决这个问题,因为我仍在 spark 的学习过程中。 我想知道,如何解决这个问题。我正在使用带有 Python 的 Spark 2.3.0
【问题讨论】:
标签: apache-spark pyspark