You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
vm$ cd ~
vm$ mkdir dev && cd dev
vm$ touch text.txt
vm$ nano text.txt #<--- paste some text in
vm$ pyspark
vm$ textFile = spark.read.text("text.txt")
count rows
vm$ textFile.count()
count words
def word_count(filename):
lines = spark.read.text(filename)
# lines.dropna()
lines = lines.filter('value != ""')
c = 0
for r in lines.collect():
c += len(r.value.split(' '))
return c
word_count('text.txt')