![](/img/trans.png)
[英]How to remove elements how to delete elemts from one rdd based on other rdd and create new rdd in pyspark?
[英]How to remove empty rows from an Pyspark RDD
我想在RDD中刪除幾行空行。 我該怎么做?
我嘗試了以下但它不起作用。 我仍然得到空行
json_cp_rdd = xform_rdd.map(lambda (key, value): get_cp_json_with_planid(key, value)).filter(
lambda x: x is not None).filter(
lambda x: x is not '')
[你,你,你,你,你,你,你,你,你,你,你,你,你,你,你,你) '',你',你',你',你',你',你',你',你',你',你',你',你''' ,你,你,你,你,你,你,你,你,你,你,你,你,你,你,你,你'',你',你',你',你',你',你',你',你',你',你',你',你''' ,你,你,你,你,你,你,你,你,你,你,你,你,你,你,你,你'',你',你',你',你',你',你',你',你',你',你',你',你''' ,你,你,你,你,你,你,你,你,你,你,你,你,你,你,你,你'',你',你',你',你',你',你',你',你',你',你',你',你''' ,你,你,你,你,你,你,你,你,你,你,你,你,你,你,你,你'',你',你',你',你',你',你',你',你',你',你',你',你''' ,你,你,你,你,你,你,你,你,你,你,你,你,你,你,你,你'',你',你',你',你',你',你',你',你',你',你',你',你''' ,你,你,你,你,你,你,你,你,你,你,你,你,你,你,你,你'',你',你',你',你',你',你',你',你',你',你',你',你''' ,u',u',u',u',u',u',u',u'[{“PLAN_ID”:“d2031aed-175f-4346-af31-9d05bfd4ea3a”,“ CostTotalInvEOPAmount“:0.0,”St oreCount“:0,”WeekEndingData“:”2017-07-08“,”UnitTotalInvBOPQuantity“:0.0,”PriceStatus“:1,”UnitOnOrderQuantity“:null,”CostTotalInvBOPAmount“:0.0,”RetailSalesAmount“:0.0,”UnitCostAmount“ :0.0,“CostReceiptAmount”:0.0,“CostSalesAmount”:0.0,“UnitSalesQuantity”:0.0,“UnitReceiptQuantity”:0.0,“UnitTotalInvEOPQuantity”:0.0,“CostOnOrderAmount”:null}]',u',u'',你,'你',你',你',你',你',你'']
is
檢查對象身份不平等。 在Python 2.x中你可以使用!=
.filter(lambda x: x is not None).filter(lambda x: x != "")
但在慣用的情況下,您只能使用帶有標識的單個filter
:
.filter(lambda x: x)
或直接與bool
:
.filter(bool)
filter(lambda x: x is not '')
替換filter(lambda x: x is not '')
filter(lambda x: x is not u'')
並且它解決了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.