Skip to content

Commit d5698f4

Browse files
add notebook magic commands
1 parent 669e346 commit d5698f4

File tree

8 files changed

+208
-3
lines changed

8 files changed

+208
-3
lines changed

Chapter5/better_pandas.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4178,7 +4178,7 @@
41784178
"name": "python",
41794179
"nbconvert_exporter": "python",
41804180
"pygments_lexer": "ipython3",
4181-
"version": "3.11.6"
4181+
"version": "3.11.4"
41824182
},
41834183
"toc": {
41844184
"base_numbering": 1,

Chapter7/jupyter_notebook.ipynb

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,82 @@
12321232
"source": [
12331233
"[Link to testbook](https://bit.ly/49dzOJ4)."
12341234
]
1235+
},
1236+
{
1237+
"cell_type": "markdown",
1238+
"id": "09df9a0c",
1239+
"metadata": {},
1240+
"source": [
1241+
"### Navigating and Managing Files in Notebooks: Top Magic Commands"
1242+
]
1243+
},
1244+
{
1245+
"cell_type": "markdown",
1246+
"id": "2734c7c2",
1247+
"metadata": {},
1248+
"source": [
1249+
"To efficiently manage folders, navigate directories, write to files, and execute scripts directly from your notebook, consider using these four highly effective magic commands that simplify these tasks:\n",
1250+
"- `%mkdir`: Create new folders.\n",
1251+
"- `%cd`: Navigate through directories.\n",
1252+
"- `%%writefile`: Write content to files.\n",
1253+
"- `%run`: Run external Python scripts."
1254+
]
1255+
},
1256+
{
1257+
"cell_type": "code",
1258+
"execution_count": 2,
1259+
"id": "34444974",
1260+
"metadata": {},
1261+
"outputs": [
1262+
{
1263+
"name": "stdout",
1264+
"output_type": "stream",
1265+
"text": [
1266+
"/Users/khuyentran/book/Efficient_Python_tricks_and_tools_for_data_scientists/Chapter7/my_project\n"
1267+
]
1268+
}
1269+
],
1270+
"source": [
1271+
"%mkdir my_project\n",
1272+
"%cd my_project"
1273+
]
1274+
},
1275+
{
1276+
"cell_type": "code",
1277+
"execution_count": 3,
1278+
"id": "0e311fd6",
1279+
"metadata": {},
1280+
"outputs": [
1281+
{
1282+
"name": "stdout",
1283+
"output_type": "stream",
1284+
"text": [
1285+
"Writing process_data.py\n"
1286+
]
1287+
}
1288+
],
1289+
"source": [
1290+
"%%writefile process_data.py\n",
1291+
"print(\"Processing data...\")"
1292+
]
1293+
},
1294+
{
1295+
"cell_type": "code",
1296+
"execution_count": 4,
1297+
"id": "aa0e53d2",
1298+
"metadata": {},
1299+
"outputs": [
1300+
{
1301+
"name": "stdout",
1302+
"output_type": "stream",
1303+
"text": [
1304+
"Processing data...\n"
1305+
]
1306+
}
1307+
],
1308+
"source": [
1309+
"%run process_data.py"
1310+
]
12351311
}
12361312
],
12371313
"metadata": {

Chapter7/my_project/process_data.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Processing data...")

docs/Chapter7/Chapter7.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
<li class="toctree-l2"><a class="reference internal" href="../Chapter2/dataclasses.html">3.7. Data Classes</a></li>
235235
<li class="toctree-l2"><a class="reference internal" href="../Chapter2/typing.html">3.8. Typing</a></li>
236236
<li class="toctree-l2"><a class="reference internal" href="../Chapter2/pathlib.html">3.9. pathlib</a></li>
237+
<li class="toctree-l2"><a class="reference internal" href="../Chapter2/pydantic.html">3.10. Pydantic</a></li>
237238
</ul>
238239
</li>
239240
<li class="toctree-l1 has-children"><a class="reference internal" href="../Chapter3/Chapter3.html">4. Pandas</a><input class="toctree-checkbox" id="toctree-checkbox-4" name="toctree-checkbox-4" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-4"><i class="fa-solid fa-chevron-down"></i></label><ul>

docs/Chapter7/jupyter_notebook.html

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@
235235
<li class="toctree-l2"><a class="reference internal" href="../Chapter2/dataclasses.html">3.7. Data Classes</a></li>
236236
<li class="toctree-l2"><a class="reference internal" href="../Chapter2/typing.html">3.8. Typing</a></li>
237237
<li class="toctree-l2"><a class="reference internal" href="../Chapter2/pathlib.html">3.9. pathlib</a></li>
238+
<li class="toctree-l2"><a class="reference internal" href="../Chapter2/pydantic.html">3.10. Pydantic</a></li>
238239
</ul>
239240
</li>
240241
<li class="toctree-l1 has-children"><a class="reference internal" href="../Chapter3/Chapter3.html">4. Pandas</a><input class="toctree-checkbox" id="toctree-checkbox-4" name="toctree-checkbox-4" type="checkbox"/><label class="toctree-toggle" for="toctree-checkbox-4"><i class="fa-solid fa-chevron-down"></i></label><ul>
@@ -523,6 +524,7 @@ <h2> Contents </h2>
523524
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#debug-your-jupyter-notebook-s-code-with-snoop">8.1.8. Debug Your Jupyter Notebook’s Code with snoop</a></li>
524525
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#integrate-jupyter-ai-for-seamless-code-creation-in-jupyter-notebook-and-lab">8.1.9. Integrate Jupyter AI for Seamless Code Creation in Jupyter Notebook and Lab</a></li>
525526
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#testbook-write-clean-unit-tests-for-notebooks">8.1.10. testbook: Write Clean Unit Tests for Notebooks</a></li>
527+
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#navigating-and-managing-files-in-notebooks-top-magic-commands">8.1.11. Navigating and Managing Files in Notebooks: Top Magic Commands</a></li>
526528
</ul>
527529
</nav>
528530
</div>
@@ -1166,6 +1168,54 @@ <h2><span class="section-number">8.1.10. </span>testbook: Write Clean Unit Tests
11661168
</div>
11671169
<p><a class="reference external" href="https://bit.ly/49dzOJ4">Link to testbook</a>.</p>
11681170
</section>
1171+
<section id="navigating-and-managing-files-in-notebooks-top-magic-commands">
1172+
<h2><span class="section-number">8.1.11. </span>Navigating and Managing Files in Notebooks: Top Magic Commands<a class="headerlink" href="#navigating-and-managing-files-in-notebooks-top-magic-commands" title="Permalink to this heading">#</a></h2>
1173+
<p>To efficiently manage folders, navigate directories, write to files, and execute scripts directly from your notebook, consider using these four highly effective magic commands that simplify these tasks:</p>
1174+
<ul class="simple">
1175+
<li><p><code class="docutils literal notranslate"><span class="pre">%mkdir</span></code>: Create new folders.</p></li>
1176+
<li><p><code class="docutils literal notranslate"><span class="pre">%cd</span></code>: Navigate through directories.</p></li>
1177+
<li><p><code class="docutils literal notranslate"><span class="pre">%%writefile</span></code>: Write content to files.</p></li>
1178+
<li><p><code class="docutils literal notranslate"><span class="pre">%run</span></code>: Run external Python scripts.</p></li>
1179+
</ul>
1180+
<div class="cell docutils container">
1181+
<div class="cell_input docutils container">
1182+
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="o">%</span><span class="k">mkdir</span> my_project
1183+
<span class="o">%</span><span class="k">cd</span> my_project
1184+
</pre></div>
1185+
</div>
1186+
</div>
1187+
<div class="cell_output docutils container">
1188+
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/khuyentran/book/Efficient_Python_tricks_and_tools_for_data_scientists/Chapter7/my_project
1189+
</pre></div>
1190+
</div>
1191+
</div>
1192+
</div>
1193+
<div class="cell docutils container">
1194+
<div class="cell_input docutils container">
1195+
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="o">%%writefile</span> process_data.py
1196+
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Processing data...&quot;</span><span class="p">)</span>
1197+
</pre></div>
1198+
</div>
1199+
</div>
1200+
<div class="cell_output docutils container">
1201+
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Writing process_data.py
1202+
</pre></div>
1203+
</div>
1204+
</div>
1205+
</div>
1206+
<div class="cell docutils container">
1207+
<div class="cell_input docutils container">
1208+
<div class="highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="o">%</span><span class="k">run</span> process_data.py
1209+
</pre></div>
1210+
</div>
1211+
</div>
1212+
<div class="cell_output docutils container">
1213+
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Processing data...
1214+
</pre></div>
1215+
</div>
1216+
</div>
1217+
</div>
1218+
</section>
11691219
</section>
11701220

11711221
<script type="text/x-thebe-config">
@@ -1232,6 +1282,7 @@ <h2><span class="section-number">8.1.10. </span>testbook: Write Clean Unit Tests
12321282
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#debug-your-jupyter-notebook-s-code-with-snoop">8.1.8. Debug Your Jupyter Notebook’s Code with snoop</a></li>
12331283
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#integrate-jupyter-ai-for-seamless-code-creation-in-jupyter-notebook-and-lab">8.1.9. Integrate Jupyter AI for Seamless Code Creation in Jupyter Notebook and Lab</a></li>
12341284
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#testbook-write-clean-unit-tests-for-notebooks">8.1.10. testbook: Write Clean Unit Tests for Notebooks</a></li>
1285+
<li class="toc-h2 nav-item toc-entry"><a class="reference internal nav-link" href="#navigating-and-managing-files-in-notebooks-top-magic-commands">8.1.11. Navigating and Managing Files in Notebooks: Top Magic Commands</a></li>
12351286
</ul>
12361287
</nav></div>
12371288

docs/_sources/Chapter5/better_pandas.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4178,7 +4178,7 @@
41784178
"name": "python",
41794179
"nbconvert_exporter": "python",
41804180
"pygments_lexer": "ipython3",
4181-
"version": "3.11.6"
4181+
"version": "3.11.4"
41824182
},
41834183
"toc": {
41844184
"base_numbering": 1,

docs/_sources/Chapter7/jupyter_notebook.ipynb

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,82 @@
12321232
"source": [
12331233
"[Link to testbook](https://bit.ly/49dzOJ4)."
12341234
]
1235+
},
1236+
{
1237+
"cell_type": "markdown",
1238+
"id": "09df9a0c",
1239+
"metadata": {},
1240+
"source": [
1241+
"### Navigating and Managing Files in Notebooks: Top Magic Commands"
1242+
]
1243+
},
1244+
{
1245+
"cell_type": "markdown",
1246+
"id": "2734c7c2",
1247+
"metadata": {},
1248+
"source": [
1249+
"To efficiently manage folders, navigate directories, write to files, and execute scripts directly from your notebook, consider using these four highly effective magic commands that simplify these tasks:\n",
1250+
"- `%mkdir`: Create new folders.\n",
1251+
"- `%cd`: Navigate through directories.\n",
1252+
"- `%%writefile`: Write content to files.\n",
1253+
"- `%run`: Run external Python scripts."
1254+
]
1255+
},
1256+
{
1257+
"cell_type": "code",
1258+
"execution_count": 2,
1259+
"id": "34444974",
1260+
"metadata": {},
1261+
"outputs": [
1262+
{
1263+
"name": "stdout",
1264+
"output_type": "stream",
1265+
"text": [
1266+
"/Users/khuyentran/book/Efficient_Python_tricks_and_tools_for_data_scientists/Chapter7/my_project\n"
1267+
]
1268+
}
1269+
],
1270+
"source": [
1271+
"%mkdir my_project\n",
1272+
"%cd my_project"
1273+
]
1274+
},
1275+
{
1276+
"cell_type": "code",
1277+
"execution_count": 3,
1278+
"id": "0e311fd6",
1279+
"metadata": {},
1280+
"outputs": [
1281+
{
1282+
"name": "stdout",
1283+
"output_type": "stream",
1284+
"text": [
1285+
"Writing process_data.py\n"
1286+
]
1287+
}
1288+
],
1289+
"source": [
1290+
"%%writefile process_data.py\n",
1291+
"print(\"Processing data...\")"
1292+
]
1293+
},
1294+
{
1295+
"cell_type": "code",
1296+
"execution_count": 4,
1297+
"id": "aa0e53d2",
1298+
"metadata": {},
1299+
"outputs": [
1300+
{
1301+
"name": "stdout",
1302+
"output_type": "stream",
1303+
"text": [
1304+
"Processing data...\n"
1305+
]
1306+
}
1307+
],
1308+
"source": [
1309+
"%run process_data.py"
1310+
]
12351311
}
12361312
],
12371313
"metadata": {

docs/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)