{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "notes" }, "tags": [ "setup" ] }, "source": [ "(c) 2016 - present. Enplus Advisors, Inc." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "skip" }, "tags": [ "setup" ] }, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "slideshow": { "slide_type": "slide" }, "tags": [ "setup" ] }, "outputs": [], "source": [ "df = pd.DataFrame({\n", " 'ticker': ['AAPL', 'AAPL', 'MSFT', 'IBM', 'YHOO'],\n", " 'date': ['2015-12-30', '2015-12-31', '2015-12-30', '2015-12-30', '2015-12-30'],\n", " 'open': [426.23, 427.81, 42.3, 101.65, 35.53]\n", "})" ] }, { "cell_type": "markdown", "metadata": { "tags": [ "exercise" ] }, "source": [ "**Exercise:**\n", "\n", "* Select the `open` column as a `Series` using attribute lookup\n", "* Select the `open` column as a `Series` using `dict`-style lookup\n", "* Select the `date` column as a `DataFrame`" ] }, { "cell_type": "markdown", "metadata": { "tags": [ "exercise" ] }, "source": [ "**Exercise:**\n", "\n", "* Select all rows with the `AAPL` ticker and the `date` and `open`\n", " columns.\n", "* Assign to the variable `df1` a new `DataFrame` with `ticker` as\n", " the index.\n", "* Assign to the variable `df2` a new `DataFrame` with `date` as\n", " the index. Create this `DataFrame` from `df1` with a single\n", " statement.\n", "* Sort `df2` by the index values." ] }, { "cell_type": "markdown", "metadata": { "tags": [ "exercise" ] }, "source": [ "**Exercise:**\n", "\n", "* Create a copy of `df` called `df3`. Add a new column of `NaNs` \n", " to `df3` called `close`. Assign `close` the same value as `open`\n", " for all `open` values greater than 100.\n", "* Sort `df3` by its `close` values." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 1 }