forked from swcarpentry/python-novice-inflammation
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
131 lines (129 loc) · 7.46 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="pandoc">
<title>Software Carpentry: Programming with Python</title>
<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap-theme.css" />
<link rel="stylesheet" type="text/css" href="css/swc.css" />
<link rel="alternate" type="application/rss+xml" title="Software Carpentry Blog" href="http://software-carpentry.org/feed.xml"/>
<meta charset="UTF-8" />
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body class="lesson">
<div class="container card">
<div class="banner">
<a href="http://software-carpentry.org" title="Software Carpentry">
<img alt="Software Carpentry banner" src="img/software-carpentry-banner.png" />
</a>
</div>
<article>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<h1 class="title">Programming with Python</h1>
<p>The best way to learn how to program is to do something useful, so this introduction to Python is built around a common scientific task: data analysis.</p>
<p>Our real goal isn’t to teach you Python, but to teach you the basic concepts that all programming depends on. We use Python in our lessons because:</p>
<ol style="list-style-type: decimal">
<li>we have to use <em>something</em> for examples;</li>
<li>it’s free, well-documented, and runs almost everywhere;</li>
<li>it has a large (and growing) user base among scientists; and</li>
<li>experience shows that it’s easier for novices to pick up than most other languages.</li>
</ol>
<p>But the two most important things are to use whatever language your colleagues are using, so that you can share your work with them easily, and to use that language <em>well</em>.</p>
<p>We are studying inflammation in patients who have been given a new treatment for arthritis, and need to analyze the first dozen data sets of their daily inflammation. The data sets are stored in <a href="reference.html#comma-separated-values">comma-separated values</a> (CSV) format: each row holds information for a single patient, and the columns represent successive days. The first few rows of our first file look like this:</p>
<pre><code>0,0,1,3,1,2,4,7,8,3,3,3,10,5,7,4,7,7,12,18,6,13,11,11,7,7,4,6,8,8,4,4,5,7,3,4,2,3,0,0
0,1,2,1,2,1,3,2,2,6,10,11,5,9,4,4,7,16,8,6,18,4,12,5,12,7,11,5,11,3,3,5,4,4,5,5,1,1,0,1
0,1,1,3,3,2,6,2,5,9,5,7,4,5,4,15,5,11,9,10,19,14,12,17,7,12,11,7,4,2,10,5,4,2,2,3,2,2,1,1
0,0,2,0,4,2,2,1,6,7,10,7,9,13,8,8,15,10,10,7,17,4,4,7,6,15,6,4,9,11,3,5,6,3,3,4,2,3,2,1
0,1,1,3,3,1,3,5,2,4,4,7,6,5,3,10,8,10,6,17,9,14,9,7,13,9,12,6,7,7,9,6,3,2,2,4,2,0,1,1</code></pre>
<p>We want to:</p>
<ul>
<li>load that data into memory,</li>
<li>calculate the average inflammation per day across all patients, and</li>
<li>plot the result.</li>
</ul>
<p>To do all that, we’ll have to learn a little bit about programming.</p>
<section class="prereq panel panel-warning">
<div class="panel-heading">
<h2 id="prerequisites"><span class="glyphicon glyphicon-education"></span>Prerequisites</h2>
</div>
<div class="panel-body">
<p>Learners need to understand the concepts of files and directories (including the working directory) and how to start a Python interpreter before tackling this lesson. This lesson references the Jupyter (IPython) Notebook although it can be taught through any Python interpreter. The commands in this lesson pertain to <strong>Python 3</strong>.</p>
</div>
</section>
<section class="getready panel panel-warning">
<div class="panel-heading">
<h2 id="getting-ready"><span class="glyphicon glyphicon-check"></span>Getting ready</h2>
</div>
<div class="panel-body">
<p>You need to download some files to follow this lesson:</p>
<ol style="list-style-type: decimal">
<li>Make a new folder in your Desktop called <code>python-novice-inflammation</code>.</li>
<li>Download <a href="./python-novice-inflammation-data.zip">python-novice-inflammation-data.zip</a> and move the file to this folder.</li>
<li>If it’s not unzipped yet, double-click on it to unzip it. You should end up with a new folder called <code>data</code>.</li>
<li>You can access this folder from the Unix shell with:</li>
</ol>
<pre class="input"><code>$ cd && cd Desktop/python-novice-inflammation/data</code></pre>
</div>
</section>
<section class="getready panel panel-warning">
<div class="panel-heading">
<h2 id="starting-python"><span class="glyphicon glyphicon-check"></span>Starting Python</h2>
</div>
<div class="panel-body">
<p>If you will be using the Jupyter (IPython) notebook for the lesson, you should have already <a href="http://swcarpentry.github.io/workshop-template/#setup">installed Anaconda</a> which includes the notebook.</p>
<p>To start the notebook, open a terminal or git bash and type the command:</p>
<pre class="input"><code>$ jupyter notebook</code></pre>
<p>To start the Python intrepreter without the notebook, open a terminal or git bash and type the command:</p>
<pre class="input"><code>$ python</code></pre>
</div>
</section>
<h2 id="topics">Topics</h2>
<ol style="list-style-type: decimal">
<li><a href="01-numpy.html">Analyzing Patient Data</a></li>
<li><a href="02-loop.html">Repeating Actions with Loops</a></li>
<li><a href="03-lists.html">Storing Multiple Values in Lists</a></li>
<li><a href="04-files.html">Analyzing Data from Multiple Files</a></li>
<li><a href="05-cond.html">Making Choices</a></li>
<li><a href="06-func.html">Creating Functions</a></li>
<li><a href="07-errors.html">Errors and Exceptions</a></li>
<li><a href="08-defensive.html">Defensive Programming</a></li>
<li><a href="09-debugging.html">Debugging</a></li>
<li><a href="10-cmdline.html">Command-Line Programs</a></li>
</ol>
<h2 id="other-resources">Other Resources</h2>
<ul>
<li><a href="reference.html">Reference</a></li>
<li><a href="discussion.html">Discussion</a></li>
<li><a href="instructors.html">Instructor’s Guide</a></li>
</ul>
</div>
</div>
</article>
<div class="footer">
<a class="label swc-blue-bg" href="http://software-carpentry.org">Software Carpentry</a>
<a class="label swc-blue-bg" href="https://github.com/swcarpentry/python-novice-inflammation">Source</a>
<a class="label swc-blue-bg" href="mailto:[email protected]">Contact</a>
<a class="label swc-blue-bg" href="LICENSE.html">License</a>
</div>
</div>
<!-- Javascript placed at the end of the document so the pages load faster -->
<script src="http://software-carpentry.org/v5/js/jquery-1.9.1.min.js"></script>
<script src="css/bootstrap/bootstrap-js/bootstrap.js"></script>
<script src='https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-37305346-2', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>