Skip to content

Instantly share code, notes, and snippets.

@sirwart
Last active August 15, 2016 06:25
Show Gist options
  • Save sirwart/47dbded317a1b5d409bc2636e86edb62 to your computer and use it in GitHub Desktop.
Save sirwart/47dbded317a1b5d409bc2636e86edb62 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Correlation between SF rental rate and homelessness"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"r_value: 0.373609695268\n",
"p_value: 0.257710359871\n",
"\n",
"r_value2: 0.432365769157\n"
]
}
],
"source": [
"import csv\n",
"import requests\n",
"import scipy.stats\n",
"\n",
"resp = requests.get(\"https://numeracy.co/projects/5S3mIklNmpw/sf-rentals-by-district.csv\")\n",
"\n",
"rows = csv.DictReader(resp.text.splitlines())\n",
"\n",
"x = []\n",
"y = []\n",
"y2 = []\n",
"for row in rows:\n",
" x.append(float(row[\"% rentals\"]))\n",
" y.append(float(row[\"number of homeless\"]))\n",
" y2.append(float(row[\"homeless per sq mile\"]))\n",
"\n",
"slope, intercept, r_value, p_value, std_err = scipy.stats.linregress(x, y)\n",
"slope2, intercept2, r_value2, p_value2, std_err2 = scipy.stats.linregress(x, y2)\n",
"\n",
"print \"r_value: \" + str(r_value)\n",
"print \"p_value: \" + str(p_value)\n",
"\n",
"print \"\\nr_value2: \" + str(r_value2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment