index.html 12.7 KB
Newer Older
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="last-modified" content="2017-08-04 00:20:27 +0200">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- meta "search-domain" used for google site search function google_search() -->
    <meta name="search-domain" value="/swc-releases/2017.08/python-novice-inflammation">
    <link rel="stylesheet" type="text/css" href="./assets/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="./assets/css/bootstrap-theme.css" />
    <link rel="stylesheet" type="text/css" href="./assets/css/lesson.css" />
    
    <link rel="shortcut icon" type="image/x-icon" href="/favicon-swc.ico" />
    
    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
	<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
	<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
	<![endif]-->
    <title>Programming with Python</title>
  </head>
  <body>
    <div class="container">
      
<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>

      
      

      
      <a class="navbar-brand" href="./">Home</a>

    </div>
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">

	
        <li><a href="./conduct/">Code of Conduct</a></li>

	
        
        <li><a href="./setup/">Setup</a></li>
        <li class="dropdown">
          <a href="./" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Episodes <span class="caret"></span></a>
          <ul class="dropdown-menu">
            
            <li><a href="./01-numpy/">Analyzing Patient Data</a></li>
            
            <li><a href="./02-loop/">Repeating Actions with Loops</a></li>
            
            <li><a href="./03-lists/">Storing Multiple Values in Lists</a></li>
            
            <li><a href="./04-files/">Analyzing Data from Multiple Files</a></li>
            
            <li><a href="./05-cond/">Making Choices</a></li>
            
            <li><a href="./06-func/">Creating Functions</a></li>
            
            <li><a href="./07-errors/">Errors and Exceptions</a></li>
            
            <li><a href="./08-defensive/">Defensive Programming</a></li>
            
            <li><a href="./09-debugging/">Debugging</a></li>
            
            <li><a href="./10-cmdline/">Command-Line Programs</a></li>
            
	    <li role="separator" class="divider"></li>
            <li><a href="./aio/">All in one page (Beta)</a></li>
          </ul>
        </li>
	

	
	
        <li class="dropdown">
          <a href="./" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Extras <span class="caret"></span></a>
          <ul class="dropdown-menu">
            <li><a href="./reference/">Reference</a></li>
            
            <li><a href="./about/">About</a></li>
            
            <li><a href="./discuss/">Discussion</a></li>
            
            <li><a href="./figures/">Figures</a></li>
            
            <li><a href="./guide/">Instructor Notes</a></li>
            
          </ul>
        </li>
	

	
        <li><a href="./license/">License</a></li>
	
	<li><a href="/edit/gh-pages/index.md">Improve this page <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a></li>
	
      </ul>
      <form class="navbar-form navbar-right" role="search" id="search" onsubmit="google_search(); return false;">
        <div class="form-group">
          <input type="text" id="google-search" placeholder="Search..." aria-label="Google site search">
        </div>
      </form>
    </div>
  </div>
</nav>


<h1 class="maintitle"><a href="./">Programming with Python</a></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>
  <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/#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>

<div class="source highlighter-rouge"><pre class="highlight"><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>
</div>

<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>

<blockquote class="prereq">
  <h2 id="prerequisites">Prerequisites</h2>

  <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>
</blockquote>

<h3 id="getting-started">Getting Started</h3>
<p>To get started, follow the directions in the “<a href="setup/">Setup</a>” tab to download data to your computer and follow any installation instructions.</p>


<div class="syllabus">
  <h2 id="schedule">Schedule</h2>

  
  
  
  
    
  
    
  
    
  
    
  
    
  
    
  
    
  
    
  
    
  
    
  
  

  <table class="table table-striped">
  <tr>
    
    <td class="col-md-2"></td>
    <td class="col-md-3"><a href="./setup">Setup</a></td>
    <td class="col-md-7">Download files required for the lesson</td>
  </tr>
  
    
    
    
    <tr>
      
      <td class="col-md-2">00:00</td>
      <td class="col-md-3">
        
	1. <a href="./01-numpy/">Analyzing Patient Data</a>
      </td>
      <td class="col-md-7">
        
          
            
              How can I process tabular data files in Python?

              
            
          
        
      </td>
    </tr>
    
  
    
    
    
    <tr>
      
      <td class="col-md-2">00:30</td>
      <td class="col-md-3">
        
	2. <a href="./02-loop/">Repeating Actions with Loops</a>
      </td>
      <td class="col-md-7">
        
          
            
              How can I do the same operations on many different values?

              
            
          
        
      </td>
    </tr>
    
  
    
    
    
    <tr>
      
      <td class="col-md-2">01:00</td>
      <td class="col-md-3">
        
	3. <a href="./03-lists/">Storing Multiple Values in Lists</a>
      </td>
      <td class="col-md-7">
        
          
            
              How can I store many values together?

              
            
          
        
      </td>
    </tr>
    
  
    
    
    
    <tr>
      
      <td class="col-md-2">01:30</td>
      <td class="col-md-3">
        
	4. <a href="./04-files/">Analyzing Data from Multiple Files</a>
      </td>
      <td class="col-md-7">
        
          
            
              How can I do the same operations on many different files?

              
            
          
        
      </td>
    </tr>
    
  
    
    
    
    <tr>
      
      <td class="col-md-2">01:50</td>
      <td class="col-md-3">
        
	5. <a href="./05-cond/">Making Choices</a>
      </td>
      <td class="col-md-7">
        
          
            
              How can my programs do different things based on data values?

              
            
          
        
      </td>
    </tr>
    
  
    
    
    
    <tr>
      
      <td class="col-md-2">02:20</td>
      <td class="col-md-3">
        
	6. <a href="./06-func/">Creating Functions</a>
      </td>
      <td class="col-md-7">
        
          
            
              How can I define new functions?

              
              <br/>
              
            
              What’s the difference between defining and calling a function?

              
              <br/>
              
            
              What happens when I call a function?

              
            
          
        
      </td>
    </tr>
    
  
    
    
    
    <tr>
      
      <td class="col-md-2">02:50</td>
      <td class="col-md-3">
        
	7. <a href="./07-errors/">Errors and Exceptions</a>
      </td>
      <td class="col-md-7">
        
          
            
              How does Python report errors?

              
              <br/>
              
            
              How can I handle errors in Python programs?

              
            
          
        
      </td>
    </tr>
    
  
    
    
    
    <tr>
      
      <td class="col-md-2">03:20</td>
      <td class="col-md-3">
        
	8. <a href="./08-defensive/">Defensive Programming</a>
      </td>
      <td class="col-md-7">
        
          
            
              How can I make my programs more reliable?

              
            
          
        
      </td>
    </tr>
    
  
    
    
    
    <tr>
      
      <td class="col-md-2">03:50</td>
      <td class="col-md-3">
        
	9. <a href="./09-debugging/">Debugging</a>
      </td>
      <td class="col-md-7">
        
          
            
              How can I debug my program?

              
            
          
        
      </td>
    </tr>
    
  
    
    
    
    <tr>
      
      <td class="col-md-2">04:20</td>
      <td class="col-md-3">
        
	10. <a href="./10-cmdline/">Command-Line Programs</a>
      </td>
      <td class="col-md-7">
        
          
            
              How can I write Python programs that will work like Unix command-line tools?

              
            
          
        
      </td>
    </tr>
    
  
  
  
  <tr>
    
    <td class="col-md-2">04:50</td>
    <td class="col-md-3">Finish</td>
    <td class="col-md-7"></td>
  </tr>
  </table>

  <p>
    The actual schedule may vary slightly depending on the topics and exercises chosen by the instructor.
  </p>

</div>


      
      
<footer>
  <div class="row">
    <div class="col-md-6" align="left">
      <h4>
	Copyright &copy; 2016–2017
	
	<a href="https://software-carpentry.org">Software Carpentry Foundation</a>
	
      </h4>
    </div>
    <div class="col-md-6" align="right">
      <h4>
	
	<a href="/edit/gh-pages/index.md">Edit on GitHub</a>
	
	/
	<a href="/blob/gh-pages/CONTRIBUTING.md">Contributing</a>
	/
	<a href="/">Source</a>
	/
	<a href="/blob/gh-pages/CITATION">Cite</a>
	/
	<a href="">Contact</a>
      </h4>
    </div>
  </div>
</footer>

      
    </div>
    
<script src="./assets/js/jquery.min.js"></script>
<script src="./assets/js/bootstrap.min.js"></script>
<script src="./assets/js/lesson.js"></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>