Notebook配置使用PySpark



pyspark代码示例:

#方法2需要复制这三行
import findspark
findspark.init()
import pyspark

#方法1直接从这里开始复制
import random
sc = pyspark.SparkContext(appName="Pi")
num_samples = 100000000
def inside(p):
x, y = random.random(), random.random()
return x*x + y*y < 1
count = sc.parallelize(range(0, num_samples)).filter(inside).count()
pi = 4 * count / num_samples
print(pi)
sc.stop()