June 2017
Beginner to intermediate
296 pages
7h 4m
English
Finally, we need to call the collect action to actually kick it all off and make Spark go do something and collect the results into a regular Python list called results:
results = minTemps.collect();
We'll just iterate through that and print them out:
for result in results:
print(result[0] + "\t{:.2f}F".format(result[1]))
We'll do a little bit of fancy formatting here. If you're new to Python, this is just saying that we're going to print the weather station identifier string, followed by a tab character, then by some formatting to ensure that the actual temperature is truncated to 2 decimal places to the right of the decimal point. We'll stick the letter F at the end just to indicate that the result is in Fahrenheit ...
Read now
Unlock full access