简体   繁体   中英

Remove elements from RDD starting with certain character

I am working with an RDD which has few lines which start with #. I want to remove all these lines which begin with # and keep remaining ones. I tried remove = records.filter(lambda x: x[0].startswith('#')) but this way it filters only the rows containing #. I want the opposite.

Try inverting your condition:

records.filter(lambda x: not x[0].startswith('#'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM