|
@@ -39,6 +39,16 @@
|
|
|
"metadata": {},
|
|
|
"outputs": [],
|
|
|
"source": [
|
|
|
+ "# Access by slice\n",
|
|
|
+ "python_list[2:5]"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
"# Loop\n",
|
|
|
"for number in python_list:\n",
|
|
|
" print(number)"
|
|
@@ -251,6 +261,45 @@
|
|
|
"cell_type": "markdown",
|
|
|
"metadata": {},
|
|
|
"source": [
|
|
|
+ "<div class=\"alert alert-success\">\n",
|
|
|
+ " <p><b>EXERCISE 1:</b> Fibonacci numbers</p>\n",
|
|
|
+ " <p>Tasks:\n",
|
|
|
+ " <ul>\n",
|
|
|
+ " <li>Create a Series with the first 10 Fibonacci numbers.</li>\n",
|
|
|
+ " <li>Compute the squared number of each of them.</li> \n",
|
|
|
+ " <li>Compute the sum of the last 4.</li>\n",
|
|
|
+ " </ul>\n",
|
|
|
+ " </p>\n",
|
|
|
+ " <p>Hints:\n",
|
|
|
+ " <ul>\n",
|
|
|
+ " <li>You can compute the Fibonacci numbers with Python, or just write the first 10 manually.</li>\n",
|
|
|
+ " <li>The Fibonacci sequence defines each element as the sum of the two previous, starting by <code>[1, 1]</code>.</li>\n",
|
|
|
+ " <li>In Python you can compute the square of a number with <code>x ** 2</code>.</li>\n",
|
|
|
+ " </ul>\n",
|
|
|
+ " </p>\n",
|
|
|
+ "</div>"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": []
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "%load solutions/data_structures_1.py"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "markdown",
|
|
|
+ "metadata": {},
|
|
|
+ "source": [
|
|
|
"### Data types"
|
|
|
]
|
|
|
},
|
|
@@ -408,6 +457,45 @@
|
|
|
"cell_type": "markdown",
|
|
|
"metadata": {},
|
|
|
"source": [
|
|
|
+ "<div class=\"alert alert-success\">\n",
|
|
|
+ " <p><b>EXERCISE 2:</b> Performance of int vs float</p>\n",
|
|
|
+ " <p>Tasks:\n",
|
|
|
+ " <ul>\n",
|
|
|
+ " <li>Create a Series of 10 million of unsigned integers of 8 bits.</li>\n",
|
|
|
+ " <li>Create a Series of 10 million of floats of 64 bits.</li> \n",
|
|
|
+ " <li>Compare the performance when computing the mean in both Series.</li>\n",
|
|
|
+ " </ul>\n",
|
|
|
+ " </p>\n",
|
|
|
+ " <p>Hints:\n",
|
|
|
+ " <ul>\n",
|
|
|
+ " <li>Signed integers are able to represent positive and negative numbers. Unsigned only positives and the number zero.</li>\n",
|
|
|
+ " <li>Unsigned integers have the prefix `u` (`uint` vs `int`).</li>\n",
|
|
|
+ " <li>NumPy types have often as a suffix the number of bits (e.g. `uint32`, `float16`).</li>\n",
|
|
|
+ " </ul>\n",
|
|
|
+ " </p>\n",
|
|
|
+ "</div>"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": []
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "code",
|
|
|
+ "execution_count": null,
|
|
|
+ "metadata": {},
|
|
|
+ "outputs": [],
|
|
|
+ "source": [
|
|
|
+ "%load solutions/data_structures_1.py"
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ "cell_type": "markdown",
|
|
|
+ "metadata": {},
|
|
|
+ "source": [
|
|
|
"### pandas DataFrame"
|
|
|
]
|
|
|
},
|