summaryrefslogtreecommitdiffhomepage
path: root/pythonstatcomp.html.markdown
diff options
context:
space:
mode:
authorJohn Gabriele <jgabriele@fastmail.fm>2018-09-10 02:05:03 -0400
committerJohn Gabriele <jgabriele@fastmail.fm>2018-09-10 02:05:03 -0400
commit3cfdf5777266d780a211cdad1c52755170097cc8 (patch)
tree8a269e1679f14ceac7a10c0592fa14bb947e5208 /pythonstatcomp.html.markdown
parent60eac5d50054ddae92bd23fb51f3acc1c306a762 (diff)
parent6d087ae0f289e7013807639cbd609f991f968166 (diff)
Merge remote-tracking branch 'origin/master' into patch-1
Diffstat (limited to 'pythonstatcomp.html.markdown')
-rw-r--r--pythonstatcomp.html.markdown18
1 files changed, 8 insertions, 10 deletions
diff --git a/pythonstatcomp.html.markdown b/pythonstatcomp.html.markdown
index 6dde1cf0..2440d859 100644
--- a/pythonstatcomp.html.markdown
+++ b/pythonstatcomp.html.markdown
@@ -38,18 +38,16 @@ r.text # raw page source
print(r.text) # prettily formatted
# save the page source in a file:
os.getcwd() # check what's the working directory
-f = open("learnxinyminutes.html", "wb")
-f.write(r.text.encode("UTF-8"))
-f.close()
+with open("learnxinyminutes.html", "wb") as f:
+ f.write(r.text.encode("UTF-8"))
# downloading a csv
fp = "https://raw.githubusercontent.com/adambard/learnxinyminutes-docs/master/"
fn = "pets.csv"
r = requests.get(fp + fn)
print(r.text)
-f = open(fn, "wb")
-f.write(r.text.encode("UTF-8"))
-f.close()
+with open(fn, "wb") as f:
+ f.write(r.text.encode("UTF-8"))
""" for more on the requests module, including APIs, see
http://docs.python-requests.org/en/latest/user/quickstart/
@@ -71,8 +69,8 @@ pets
# 1 vesuvius 6 23 fish
# 2 rex 5 34 dog
-""" R users: note that Python, like most normal programming languages, starts
- indexing from 0. R is the unusual one for starting from 1.
+""" R users: note that Python, like most C-influenced programming languages, starts
+ indexing from 0. R starts indexing at 1 due to Fortran influence.
"""
# two different ways to print out a column
@@ -205,7 +203,7 @@ hre["DeathY"] = extractYear(hre.Death)
hre["EstAge"] = hre.DeathY.astype(int) - hre.BirthY.astype(int)
# simple scatterplot, no trend line, color represents dynasty
-sns.lmplot("BirthY", "EstAge", data=hre, hue="Dynasty", fit_reg=False);
+sns.lmplot("BirthY", "EstAge", data=hre, hue="Dynasty", fit_reg=False)
# use scipy to run a linear regression
from scipy import stats
@@ -222,7 +220,7 @@ rval**2 # 0.020363950027333586
pval # 0.34971812581498452
# use seaborn to make a scatterplot and plot the linear regression trend line
-sns.lmplot("BirthY", "EstAge", data=hre);
+sns.lmplot("BirthY", "EstAge", data=hre)
""" For more information on seaborn, see
- http://web.stanford.edu/~mwaskom/software/seaborn/