Created
April 14, 2019 17:34
-
-
Save ksingh7/00d5b10a966d6fca3a344a70bce39091 to your computer and use it in GitHub Desktop.
pyspark-test.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import pyspark\n", | |
"sc = pyspark.SparkContext('local[*]')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"3.14136904\n" | |
] | |
} | |
], | |
"source": [ | |
"import random\n", | |
"num_samples = 100000000\n", | |
"def inside(p): \n", | |
" x, y = random.random(), random.random()\n", | |
" return x*x + y*y < 1\n", | |
"count = sc.parallelize(range(0, num_samples)).filter(inside).count()\n", | |
"pi = 4 * count / num_samples\n", | |
"print(pi)\n", | |
"sc.stop()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment