Skip to content

Commit

Permalink
added pdf link to pandas cheatsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
kcaylor committed Sep 6, 2024
1 parent b144815 commit df4a68f
Show file tree
Hide file tree
Showing 61 changed files with 615 additions and 614 deletions.
2 changes: 1 addition & 1 deletion cheatsheets.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ format:
- [Numpy Random Number Generation](course-materials/cheatsheets/random_numbers.qmd)

## 🐼 Pandas

- [Pandas 1-pager PDF](course-materials/cheatsheets/Pandas_Cheat_Sheet.pdf)
- [Pandas Series](course-materials/cheatsheets/pandas_series.qmd)
- [Pandas DataFrames](course-materials/cheatsheets/pandas_dataframes.qmd)
- [Pandas DataFrame Methods and Data Science Workflows](course-materials/cheatsheets/workflow_methods.qmd)
Expand Down
1 change: 1 addition & 0 deletions docs/cheatsheets.html
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ <h2 class="anchored" data-anchor-id="numpy">🔢 NumPy</h2>
<section id="pandas" class="level2">
<h2 class="anchored" data-anchor-id="pandas">🐼 Pandas</h2>
<ul>
<li><a href="course-materials/cheatsheets/Pandas_Cheat_Sheet.pdf">Pandas 1-pager PDF</a></li>
<li><a href="./course-materials/cheatsheets/pandas_series.html">Pandas Series</a></li>
<li><a href="./course-materials/cheatsheets/pandas_dataframes.html">Pandas DataFrames</a></li>
<li><a href="./course-materials/cheatsheets/workflow_methods.html">Pandas DataFrame Methods and Data Science Workflows</a></li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ <h3 class="anchored" data-anchor-id="task-1-list-operations">Task 1: List Operat
<li>Remove the second fruit from the list.</li>
<li>Print the final list.</li>
</ol>
<div id="d1af84ac" class="cell" data-execution_count="1">
<div id="f1af2434" class="cell" data-execution_count="1">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Example code for instructor</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a>fruits <span class="op">=</span> [<span class="st">"apple"</span>, <span class="st">"banana"</span>, <span class="st">"cherry"</span>]</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(<span class="st">"Original list:"</span>, fruits)</span>
Expand Down Expand Up @@ -512,7 +512,7 @@ <h3 class="anchored" data-anchor-id="task-2-dictionary-operations">Task 2: Dicti
<li>Update the quantity of an existing item.</li>
<li>Print the final inventory.</li>
</ol>
<div id="e04c6bae" class="cell" data-execution_count="2">
<div id="0e6c6dc4" class="cell" data-execution_count="2">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Example code for instructor</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a>inventory <span class="op">=</span> {</span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="st">"apples"</span>: <span class="dv">50</span>,</span>
Expand Down Expand Up @@ -549,7 +549,7 @@ <h3 class="anchored" data-anchor-id="task-3-creating-and-manipulating-sets">Task
<li>Find and print the intersection of the two sets.</li>
<li>Add a new element to the <code>evens</code> set.</li>
</ol>
<div id="5569b42d" class="cell" data-execution_count="3">
<div id="70718ab8" class="cell" data-execution_count="3">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Example code for instructor</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>evens <span class="op">=</span> {<span class="dv">2</span>, <span class="dv">4</span>, <span class="dv">6</span>, <span class="dv">8</span>, <span class="dv">10</span>}</span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>odds <span class="op">=</span> {<span class="dv">1</span>, <span class="dv">3</span>, <span class="dv">5</span>, <span class="dv">7</span>, <span class="dv">9</span>}</span>
Expand Down Expand Up @@ -583,7 +583,7 @@ <h3 class="anchored" data-anchor-id="task-4-set-operations-vs.-list-operations">
<li>Use a list comprehension to remove duplicates.</li>
<li>Print the results of both methods.</li>
</ol>
<div id="fe539044" class="cell" data-execution_count="4">
<div id="279b584e" class="cell" data-execution_count="4">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Example code for instructor</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a>numbers <span class="op">=</span> [<span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">2</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">3</span>, <span class="dv">4</span>, <span class="dv">4</span>, <span class="dv">5</span>]</span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a></span>
Expand Down
18 changes: 9 additions & 9 deletions docs/course-materials/answer-keys/3b_control_flows-key.html
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,10 @@ <h3 class="anchored" data-anchor-id="task-1-simple-weather-advice">Task 1: Simpl
<li>Otherwise, print “Enjoy the pleasant weather!”</li>
</ul></li>
</ol>
<div id="bb034449" class="cell" data-execution_count="1">
<div id="5b6951d2" class="cell" data-execution_count="1">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a>temperature <span class="op">=</span> <span class="dv">20</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div id="65ae3cf8" class="cell" data-execution_count="2">
<div id="a0ae6b54" class="cell" data-execution_count="2">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> temperature <span class="op">&gt;</span> <span class="dv">25</span>:</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="st">"It's a hot day, stay hydrated!"</span>)</span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="cf">else</span>:</span>
Expand All @@ -497,10 +497,10 @@ <h3 class="anchored" data-anchor-id="task-2-grade-classifier">Task 2: Grade Clas
<li>Below 60: “F”</li>
</ul></li>
</ol>
<div id="19bc1791" class="cell" data-execution_count="3">
<div id="d7d75eb5" class="cell" data-execution_count="3">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>score <span class="op">=</span> <span class="dv">85</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div id="2970819e" class="cell" data-execution_count="4">
<div id="e60f3c8b" class="cell" data-execution_count="4">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> score <span class="op">&gt;=</span> <span class="dv">90</span>:</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> grade <span class="op">=</span> <span class="st">'A'</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a><span class="cf">elif</span> score <span class="op">&gt;=</span> <span class="dv">80</span>:</span>
Expand Down Expand Up @@ -528,7 +528,7 @@ <h3 class="anchored" data-anchor-id="task-3-counting-sheep">Task 3: Counting She
<li>Use a for loop with the range() function</li>
<li>Print each number followed by “sheep”</li>
</ol>
<div id="a5fede66" class="cell" data-execution_count="5">
<div id="4b41e09f" class="cell" data-execution_count="5">
<div class="sourceCode cell-code" id="cb8"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">1</span>,<span class="dv">6</span>):</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="ss">f"</span><span class="sc">{</span>i<span class="sc">}</span><span class="ss"> sheep"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-stdout">
Expand All @@ -548,10 +548,10 @@ <h3 class="anchored" data-anchor-id="task-4-sum-of-numbers">Task 4: Sum of Numbe
<li>Use a for loop with the range() function to add each number to <code>total</code></li>
<li>After the loop, print the total</li>
</ol>
<div id="b1dac5d1" class="cell" data-execution_count="6">
<div id="98e2cb08" class="cell" data-execution_count="6">
<div class="sourceCode cell-code" id="cb10"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>total <span class="op">=</span> <span class="dv">0</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div id="f6a4dce2" class="cell" data-execution_count="7">
<div id="ba76fb3c" class="cell" data-execution_count="7">
<div class="sourceCode cell-code" id="cb11"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> i <span class="kw">in</span> <span class="bu">range</span>(<span class="dv">1</span>,<span class="dv">11</span>):</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> total <span class="op">=</span> total <span class="op">+</span> i</span>
<span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a></span>
Expand All @@ -573,10 +573,10 @@ <h3 class="anchored" data-anchor-id="task-5-countdown">Task 5: Countdown</h3>
<li>After each print, decrease the countdown by 1</li>
<li>When the countdown reaches 0, print “Blast off!”</li>
</ol>
<div id="937e445c" class="cell" data-execution_count="8">
<div id="73b78e95" class="cell" data-execution_count="8">
<div class="sourceCode cell-code" id="cb13"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a>countdown <span class="op">=</span> <span class="dv">5</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<div id="f6ebeff0" class="cell" data-execution_count="9">
<div id="dce37352" class="cell" data-execution_count="9">
<div class="sourceCode cell-code" id="cb14"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a><span class="cf">while</span> countdown <span class="op">&gt;</span> <span class="dv">0</span>:</span>
<span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(countdown)</span>
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a> <span class="co"># (-= is a python syntax shortcut inherited from C)</span></span>
Expand Down
10 changes: 5 additions & 5 deletions docs/course-materials/answer-keys/3d_pandas_series-key.html
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ <h2 class="anchored" data-anchor-id="resources">Resources</h2>
<section id="setup" class="level2">
<h2 class="anchored" data-anchor-id="setup">Setup</h2>
<p>First, let’s import the necessary libraries and create a sample Series.</p>
<div id="ae357629" class="cell" data-execution_count="1">
<div id="97218d1d" class="cell" data-execution_count="1">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> pandas <span class="im">as</span> pd</span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> numpy <span class="im">as</span> np</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a></span>
Expand All @@ -463,7 +463,7 @@ <h2 class="anchored" data-anchor-id="exercise-1-creating-a-series">Exercise 1: C
<blockquote class="blockquote">
<p>apple: $0.5, banana: $0.3, cherry: $1.0, date: $1.5, elderberry: $2.0</p>
</blockquote>
<div id="46360a90" class="cell" data-execution_count="2">
<div id="2fa86d5c" class="cell" data-execution_count="2">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Create a Series called 'prices' with the same index as 'fruits'</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="co"># Use these prices: apple: $0.5, banana: $0.3, cherry: $1.0, date: $1.5, elderberry: $2.0</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a>prices <span class="op">=</span> pd.Series([<span class="fl">0.5</span>, <span class="fl">0.3</span>, <span class="fl">1.0</span>, <span class="fl">2.5</span>, <span class="fl">3.0</span>], index<span class="op">=</span>fruits.values, name<span class="op">=</span><span class="st">'Prices'</span>)</span>
Expand All @@ -486,7 +486,7 @@ <h2 class="anchored" data-anchor-id="exercise-2-series-operations">Exercise 2: S
<li>Find the most expensive fruit.</li>
<li>Apply a 10% discount to all fruits priced over 1.0.</li>
</ol>
<div id="060da12a" class="cell" data-execution_count="3">
<div id="a6587068" class="cell" data-execution_count="3">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 1. Calculate the total price of all fruits</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>total_price <span class="op">=</span> prices.<span class="bu">sum</span>()</span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a></span>
Expand Down Expand Up @@ -522,7 +522,7 @@ <h2 class="anchored" data-anchor-id="exercise-3-series-analysis">Exercise 3: Ser
<li>How many fruits cost less than $1.0?</li>
<li>What is the price range (difference between max and min prices)?</li>
</ol>
<div id="6ff93a76" class="cell" data-execution_count="4">
<div id="4f93557b" class="cell" data-execution_count="4">
<div class="sourceCode cell-code" id="cb7"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 1. Calculate the average price of the fruits</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a>average_price <span class="op">=</span> prices.mean()</span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a></span>
Expand Down Expand Up @@ -550,7 +550,7 @@ <h2 class="anchored" data-anchor-id="exercise-4-series-manipulation">Exercise 4:
<li>Remove ‘banana’ from both Series.</li>
<li>Sort both Series by fruit name (alphabetically).</li>
</ol>
<div id="7c3f5a37" class="cell" data-execution_count="5">
<div id="d73af0ae" class="cell" data-execution_count="5">
<div class="sourceCode cell-code" id="cb9"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="co"># 1. Add 'fig' to both Series (price: $1.2)</span></span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>fruits <span class="op">=</span> pd.concat([fruits, pd.Series([<span class="st">'fig'</span>], name<span class="op">=</span><span class="st">'Fruits'</span>)])</span>
<span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a>prices <span class="op">=</span> pd.concat([prices, pd.Series([<span class="fl">1.2</span>], index<span class="op">=</span>[<span class="st">'fig'</span>], name<span class="op">=</span><span class="st">'Prices'</span>)])</span>
Expand Down
Loading

0 comments on commit df4a68f

Please sign in to comment.