MongoDB
 SQL >> Database >  >> NoSQL >> MongoDB

Escludere i tweet vuoti con filter() in PySpark

Per un RDD come questo:

tweets = sc.parallelize(["title1", "", "title2", "title3", ""])

usa la lunghezza di ogni elemento come predicato:

tweets.filter(lambda x: len(x) > 0).count()

Se vuoi escludere anche le stringhe composte solo da spazi, lambda x: len(x.strip()) > 0 è la condizione più sicura.