|
479 | 479 | "cell_type": "markdown", |
480 | 480 | "metadata": {}, |
481 | 481 | "source": [ |
482 | | - "For errors we get without directly calling `raise`, both the class of `Error` and the message are predetermined. This is useful in some situations, but less so in others. Suppose you wrote a reverse complement function like the one below:" |
| 482 | + "For errors we get without directly calling `raise`, both the class of `Error` and the message are predetermined. This is useful in some situations, but less so in others. Suppose you wrote a reverse complement function:" |
483 | 483 | ] |
484 | 484 | }, |
485 | 485 | { |
486 | 486 | "cell_type": "code", |
487 | 487 | "execution_count": null, |
488 | 488 | "metadata": {}, |
489 | 489 | "outputs": [], |
490 | | - "source": [ |
491 | | - "def reverse_complement(dna_sequence):\n", |
492 | | - " \"\"\"Reverses the complement of a dna sequence\"\"\"\n", |
493 | | - " complements = {\"T\":\"A\", \"A\":\"T\", \"C\":\"G\", \"G\":\"C\"}\n", |
494 | | - " reverse = dna_sequence[::-1]\n", |
495 | | - " result = \"\"\n", |
496 | | - " for letter in reverse:\n", |
497 | | - " result = result + complements[letter]\n", |
498 | | - " return(result)\n", |
499 | | - "\n", |
500 | | - "help(reverse_complement)\n", |
501 | | - "print(reverse_complement(\"CAAT\"))" |
502 | | - ] |
| 490 | + "source": [] |
503 | 491 | }, |
504 | 492 | { |
505 | 493 | "cell_type": "markdown", |
|
804 | 792 | "gapminder['region'] = gapminder['region'].astype(str)\n", |
805 | 793 | "\n", |
806 | 794 | "# Method 1 for formatting the 'region' column:\n", |
807 | | - "gapminder_copy['region'] = gapminder_copy['region'].str.lstrip() # Strip white space on left\n", |
808 | | - "gapminder_copy['region'] = gapminder_copy['region'].str.rstrip() # Strip white space on right\n", |
809 | | - "gapminder_copy['region'] = gapminder_copy['region'].str.lower() # Convert to lowercase\n", |
| 795 | + "gapminder['region'] = gapminder['region'].str.lstrip() # Strip white space on left\n", |
| 796 | + "gapminder['region'] = gapminder['region'].str.rstrip() # Strip white space on right\n", |
| 797 | + "gapminder['region'] = gapminder['region'].str.lower() # Convert to lowercase\n", |
810 | 798 | "\n", |
811 | 799 | "# Method 2 for formatting the 'region' column:\n", |
812 | | - "gapminder_copy['region'] = gapminder['region'].str.lstrip().str.rstrip().str.lower() # Strip white space on left and right, and convert to lowercase\n", |
| 800 | + "gapminder['region'] = gapminder['region'].str.lstrip().str.rstrip().str.lower() # Strip white space on left and right, and convert to lowercase\n", |
813 | 801 | "\n", |
814 | | - "print(gapminder_copy['region'])" |
| 802 | + "print(gapminder['region'])" |
815 | 803 | ] |
816 | 804 | }, |
817 | 805 | { |
|
0 commit comments