Skip to content

Instantly share code, notes, and snippets.

@johnfelios
Created October 27, 2022 13:01
Show Gist options
  • Save johnfelios/30d4bbb6356a03f8c74d37b94918b4c3 to your computer and use it in GitHub Desktop.
Save johnfelios/30d4bbb6356a03f8c74d37b94918b4c3 to your computer and use it in GitHub Desktop.
Final Assignment
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<center>\n",
" <img src=\"https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/Logos/organization_logo/organization_logo.png\" width=\"300\" alt=\"cognitiveclass.ai logo\" />\n",
"</center>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h1>Extracting and Visualizing Stock Data</h1>\n",
"<h2>Description</h2>\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Extracting essential data from a dataset and displaying it is a necessary part of data science; therefore individuals can make correct decisions based on the data. In this assignment, you will extract some stock data, you will then display this data in a graph.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2>Table of Contents</h2>\n",
"<div class=\"alert alert-block alert-info\" style=\"margin-top: 20px\">\n",
" <ul>\n",
" <li>Define a Function that Makes a Graph</li>\n",
" <li>Question 1: Use yfinance to Extract Stock Data</li>\n",
" <li>Question 2: Use Webscraping to Extract Tesla Revenue Data</li>\n",
" <li>Question 3: Use yfinance to Extract Stock Data</li>\n",
" <li>Question 4: Use Webscraping to Extract GME Revenue Data</li>\n",
" <li>Question 5: Plot Tesla Stock Graph</li>\n",
" <li>Question 6: Plot GameStop Stock Graph</li>\n",
" </ul>\n",
"<p>\n",
" Estimated Time Needed: <strong>30 min</strong></p>\n",
"</div>\n",
"\n",
"<hr>\n"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: yfinance==0.1.67 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (0.1.67)\n",
"Requirement already satisfied: pandas>=0.24 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.1.67) (1.3.5)\n",
"Requirement already satisfied: requests>=2.20 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.1.67) (2.28.1)\n",
"Requirement already satisfied: lxml>=4.5.1 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.1.67) (4.9.1)\n",
"Requirement already satisfied: multitasking>=0.0.7 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.1.67) (0.0.11)\n",
"Requirement already satisfied: numpy>=1.15 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from yfinance==0.1.67) (1.21.6)\n",
"Requirement already satisfied: python-dateutil>=2.7.3 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from pandas>=0.24->yfinance==0.1.67) (2.8.2)\n",
"Requirement already satisfied: pytz>=2017.3 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from pandas>=0.24->yfinance==0.1.67) (2022.2.1)\n",
"Requirement already satisfied: charset-normalizer<3,>=2 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests>=2.20->yfinance==0.1.67) (2.1.1)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests>=2.20->yfinance==0.1.67) (2022.9.24)\n",
"Requirement already satisfied: urllib3<1.27,>=1.21.1 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests>=2.20->yfinance==0.1.67) (1.26.11)\n",
"Requirement already satisfied: idna<4,>=2.5 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests>=2.20->yfinance==0.1.67) (3.4)\n",
"Requirement already satisfied: six>=1.5 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from python-dateutil>=2.7.3->pandas>=0.24->yfinance==0.1.67) (1.16.0)\n",
"Collecting requests==2.26.0\n",
" Downloading requests-2.26.0-py2.py3-none-any.whl (62 kB)\n",
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.3/62.3 kB\u001b[0m \u001b[31m8.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
"\u001b[?25hRequirement already satisfied: certifi>=2017.4.17 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests==2.26.0) (2022.9.24)\n",
"Requirement already satisfied: urllib3<1.27,>=1.21.1 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests==2.26.0) (1.26.11)\n",
"Requirement already satisfied: idna<4,>=2.5 in /home/jupyterlab/conda/envs/python/lib/python3.7/site-packages (from requests==2.26.0) (3.4)\n",
"Collecting charset-normalizer~=2.0.0\n",
" Downloading charset_normalizer-2.0.12-py3-none-any.whl (39 kB)\n",
"Installing collected packages: charset-normalizer, requests\n",
" Attempting uninstall: charset-normalizer\n",
" Found existing installation: charset-normalizer 2.1.1\n",
" Uninstalling charset-normalizer-2.1.1:\n",
" Successfully uninstalled charset-normalizer-2.1.1\n",
" Attempting uninstall: requests\n",
" Found existing installation: requests 2.28.1\n",
" Uninstalling requests-2.28.1:\n",
" Successfully uninstalled requests-2.28.1\n",
"\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
"ibm-cos-sdk-core 2.12.0 requires requests<3.0,>=2.27.1, but you have requests 2.26.0 which is incompatible.\u001b[0m\u001b[31m\n",
"\u001b[0mSuccessfully installed charset-normalizer-2.0.12 requests-2.26.0\n",
"\n",
" __ __ __ __\n",
" / \\ / \\ / \\ / \\\n",
" / \\/ \\/ \\/ \\\n",
"███████████████/ /██/ /██/ /██/ /████████████████████████\n",
" / / \\ / \\ / \\ / \\ \\____\n",
" / / \\_/ \\_/ \\_/ \\ o \\__,\n",
" / _/ \\_____/ `\n",
" |/\n",
" ███╗ ███╗ █████╗ ███╗ ███╗██████╗ █████╗\n",
" ████╗ ████║██╔══██╗████╗ ████║██╔══██╗██╔══██╗\n",
" ██╔████╔██║███████║██╔████╔██║██████╔╝███████║\n",
" ██║╚██╔╝██║██╔══██║██║╚██╔╝██║██╔══██╗██╔══██║\n",
" ██║ ╚═╝ ██║██║ ██║██║ ╚═╝ ██║██████╔╝██║ ██║\n",
" ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝\n",
"\n",
" mamba (0.15.3) supported by @QuantStack\n",
"\n",
" GitHub: https://github.com/mamba-org/mamba\n",
" Twitter: https://twitter.com/QuantStack\n",
"\n",
"█████████████████████████████████████████████████████████████\n",
"\n",
"\n",
"Looking for: ['bs4==4.10.0']\n",
"\n",
"pkgs/main/linux-64 [> ] (--:--) No change\n",
"pkgs/main/linux-64 [====================] (00m:00s) No change\n",
"pkgs/main/noarch [> ] (--:--) No change\n",
"pkgs/main/noarch [====================] (00m:00s) No change\n",
"pkgs/r/linux-64 [> ] (--:--) No change\n",
"pkgs/r/linux-64 [====================] (00m:00s) No change\n",
"pkgs/r/noarch [> ] (--:--) No change\n",
"pkgs/r/noarch [====================] (00m:00s) No change\n",
"\n",
"Pinned packages:\n",
" - python 3.7.*\n",
"\n",
"\n",
"Transaction\n",
"\n",
" Prefix: /home/jupyterlab/conda/envs/python\n",
"\n",
" All requested packages already installed\n",
"\n"
]
}
],
"source": [
"!pip install yfinance==0.1.67\n",
"#!pip install pandas==1.3.3\n",
"#!pip install requests==2.26.0\n",
"!mamba install bs4==4.10.0 -y\n",
"#!pip install plotly==5.3.1"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import yfinance as yf\n",
"import pandas as pd\n",
"import requests\n",
"from bs4 import BeautifulSoup\n",
"import plotly.graph_objects as go\n",
"from plotly.subplots import make_subplots"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Define Graphing Function\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this section, we define the function `make_graph`. You don't have to know how the function works, you should only care about the inputs. It takes a dataframe with stock data (dataframe must contain Date and Close columns), a dataframe with revenue data (dataframe must contain Date and Revenue columns), and the name of the stock.\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def make_graph(stock_data, revenue_data, stock):\n",
" fig = make_subplots(rows=2, cols=1, shared_xaxes=True, subplot_titles=(\"Historical Share Price\", \"Historical Revenue\"), vertical_spacing = .3)\n",
" stock_data_specific = stock_data[stock_data.Date <= '2021--06-14']\n",
" revenue_data_specific = revenue_data[revenue_data.Date <= '2021-04-30']\n",
" fig.add_trace(go.Scatter(x=pd.to_datetime(stock_data_specific.Date, infer_datetime_format=True), y=stock_data_specific.Close.astype(\"float\"), name=\"Share Price\"), row=1, col=1)\n",
" fig.add_trace(go.Scatter(x=pd.to_datetime(revenue_data_specific.Date, infer_datetime_format=True), y=revenue_data_specific.Revenue.astype(\"float\"), name=\"Revenue\"), row=2, col=1)\n",
" fig.update_xaxes(title_text=\"Date\", row=1, col=1)\n",
" fig.update_xaxes(title_text=\"Date\", row=2, col=1)\n",
" fig.update_yaxes(title_text=\"Price ($US)\", row=1, col=1)\n",
" fig.update_yaxes(title_text=\"Revenue ($US Millions)\", row=2, col=1)\n",
" fig.update_layout(showlegend=False,\n",
" height=900,\n",
" title=stock,\n",
" xaxis_rangeslider_visible=True)\n",
" fig.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 1: Use yfinance to Extract Stock Data\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using the `Ticker` function enter the ticker symbol of the stock we want to extract data on to create a ticker object. The stock is Tesla and its ticker symbol is `TSLA`.\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"tesla = yf.Ticker(\"TSLA\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using the ticker object and the function `history` extract stock information and save it in a dataframe named `tesla_data`. Set the `period` parameter to `max` so we get information for the maximum amount of time.\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"tesla_data = tesla.history(period=\"max\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Reset the index** using the `reset_index(inplace=True)` function on the tesla_data DataFrame and display the first five rows of the `tesla_data` dataframe using the `head` function. Take a screenshot of the results and code from the beginning of Question 1 to the results below.\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Open</th>\n",
" <th>High</th>\n",
" <th>Low</th>\n",
" <th>Close</th>\n",
" <th>Volume</th>\n",
" <th>Dividends</th>\n",
" <th>Stock Splits</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Date</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2010-06-29</th>\n",
" <td>1.266667</td>\n",
" <td>1.666667</td>\n",
" <td>1.169333</td>\n",
" <td>1.592667</td>\n",
" <td>281494500</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010-06-30</th>\n",
" <td>1.719333</td>\n",
" <td>2.028000</td>\n",
" <td>1.553333</td>\n",
" <td>1.588667</td>\n",
" <td>257806500</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010-07-01</th>\n",
" <td>1.666667</td>\n",
" <td>1.728000</td>\n",
" <td>1.351333</td>\n",
" <td>1.464000</td>\n",
" <td>123282000</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010-07-02</th>\n",
" <td>1.533333</td>\n",
" <td>1.540000</td>\n",
" <td>1.247333</td>\n",
" <td>1.280000</td>\n",
" <td>77097000</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010-07-06</th>\n",
" <td>1.333333</td>\n",
" <td>1.333333</td>\n",
" <td>1.055333</td>\n",
" <td>1.074000</td>\n",
" <td>103003500</td>\n",
" <td>0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Open High Low Close Volume Dividends \\\n",
"Date \n",
"2010-06-29 1.266667 1.666667 1.169333 1.592667 281494500 0 \n",
"2010-06-30 1.719333 2.028000 1.553333 1.588667 257806500 0 \n",
"2010-07-01 1.666667 1.728000 1.351333 1.464000 123282000 0 \n",
"2010-07-02 1.533333 1.540000 1.247333 1.280000 77097000 0 \n",
"2010-07-06 1.333333 1.333333 1.055333 1.074000 103003500 0 \n",
"\n",
" Stock Splits \n",
"Date \n",
"2010-06-29 0.0 \n",
"2010-06-30 0.0 \n",
"2010-07-01 0.0 \n",
"2010-07-02 0.0 \n",
"2010-07-06 0.0 "
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tesla_data.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 2: Use Webscraping to Extract Tesla Revenue Data\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use the `requests` library to download the webpage [https://www.macrotrends.net/stocks/charts/TSLA/tesla/revenue](https://www.macrotrends.net/stocks/charts/TSLA/tesla/revenue?utm_medium=Exinfluencer&utm_source=Exinfluencer&utm_content=000026UJ&utm_term=10006555&utm_id=NA-SkillsNetwork-Channel-SkillsNetworkCoursesIBMDeveloperSkillsNetworkPY0220ENSkillsNetwork23455606-2022-01-01). Save the text of the response as a variable named `html_data`.\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"url = \"https://www.macrotrends.net/stocks/charts/TSLA/tesla/revenue?utm_medium=Exinfluencer&utm_source=Exinfluencer&utm_content=000026UJ&utm_term=10006555&utm_id=NA-SkillsNetwork-Channel-SkillsNetworkCoursesIBMDeveloperSkillsNetworkPY0220ENSkillsNetwork23455606-2022-01-01\"\n",
"\n",
"html_data = requests.get(url).text"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Parse the html data using `beautiful_soup`.\n"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"soup = BeautifulSoup(html_data)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using `BeautifulSoup` or the `read_html` function extract the table with `Tesla Quarterly Revenue` and store it into a dataframe named `tesla_revenue`. The dataframe should have columns `Date` and `Revenue`.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<details><summary>Click here if you need help locating the table</summary>\n",
"\n",
"```\n",
" \n",
"Below is the code to isolate the table, you will now need to loop through the rows and columns like in the previous lab\n",
" \n",
"soup.find_all(\"tbody\")[1]\n",
" \n",
"If you want to use the read_html function the table is located at index 1\n",
"\n",
"\n",
"```\n",
"\n",
"</details>\n"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "EOL while scanning string literal (3587139353.py, line 3)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"/tmp/ipykernel_68/3587139353.py\"\u001b[0;36m, line \u001b[0;32m3\u001b[0m\n\u001b[0;31m tesla_revenue=tesla_revenue.rename(columns={\"Tesla Quarterly Revenue\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m EOL while scanning string literal\n"
]
}
],
"source": [
"tesla_revenue = pd.DataFrame(columns=[\"Date\", \"Revenue\"])\n",
"\n",
"\n",
"for row in soup.find(\"tbody\").find_all('tr'):\n",
" col = row.find_all(\"td\")\n",
" date = col[0].text\n",
" Revenue = col[1].text\n",
" \n",
" # Finally we append the data of each row to the table\n",
" tesla_revenue = tesla_revenue.append({\"Date\":date, \"Revenue\":Revenue}, ignore_index=True) \n",
" \n",
" gme_revenue[\"Revenue\"] = gme_revenue['Revenue'].str.replace(',|\\$',\"\")\n",
" \n",
" \n",
" \n",
" \n",
"gme_revenue.head() \n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Execute the following line to remove the comma and dollar sign from the `Revenue` column.\n"
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/jupyterlab/conda/envs/python/lib/python3.7/site-packages/ipykernel_launcher.py:1: FutureWarning:\n",
"\n",
"The default value of regex will change from True to False in a future version.\n",
"\n"
]
}
],
"source": [
"tesla_revenue[\"Revenue\"] = tesla_revenue['Revenue'].str.replace(',|\\$',\"\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Execute the following lines to remove an null or empty strings in the Revenue column.\n"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [],
"source": [
"tesla_revenue.dropna(inplace=True)\n",
"\n",
"tesla_revenue = tesla_revenue[tesla_revenue['Revenue'] != \"\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Display the last 5 row of the `tesla_revenue` dataframe using the `tail` function. Take a screenshot of the results.\n"
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Date</th>\n",
" <th>Revenue</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>2009</td>\n",
" <td>8806</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>2008</td>\n",
" <td>7094</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>2007</td>\n",
" <td>5319</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>2006</td>\n",
" <td>3092</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>2005</td>\n",
" <td>1843</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Date Revenue\n",
"11 2009 8806\n",
"12 2008 7094\n",
"13 2007 5319\n",
"14 2006 3092\n",
"15 2005 1843"
]
},
"execution_count": 71,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"tesla_revenue.tail()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 3: Use yfinance to Extract Stock Data\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using the `Ticker` function enter the ticker symbol of the stock we want to extract data on to create a ticker object. The stock is GameStop and its ticker symbol is `GME`.\n"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
"GameStop = yf.Ticker(\"GME\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using the ticker object and the function `history` extract stock information and save it in a dataframe named `gme_data`. Set the `period` parameter to `max` so we get information for the maximum amount of time.\n"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [],
"source": [
"gme_data = GameStop.history(period=\"max\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Reset the index** using the `reset_index(inplace=True)` function on the gme_data DataFrame and display the first five rows of the `gme_data` dataframe using the `head` function. Take a screenshot of the results and code from the beginning of Question 3 to the results below.\n"
]
},
{
"cell_type": "code",
"execution_count": 102,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Open</th>\n",
" <th>High</th>\n",
" <th>Low</th>\n",
" <th>Close</th>\n",
" <th>Volume</th>\n",
" <th>Dividends</th>\n",
" <th>Stock Splits</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Date</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2002-02-13</th>\n",
" <td>1.620128</td>\n",
" <td>1.693350</td>\n",
" <td>1.603296</td>\n",
" <td>1.691666</td>\n",
" <td>76216000</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-02-14</th>\n",
" <td>1.712707</td>\n",
" <td>1.716074</td>\n",
" <td>1.670626</td>\n",
" <td>1.683251</td>\n",
" <td>11021600</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-02-15</th>\n",
" <td>1.683251</td>\n",
" <td>1.687459</td>\n",
" <td>1.658002</td>\n",
" <td>1.674834</td>\n",
" <td>8389600</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-02-19</th>\n",
" <td>1.666417</td>\n",
" <td>1.666417</td>\n",
" <td>1.578047</td>\n",
" <td>1.607504</td>\n",
" <td>7410400</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2002-02-20</th>\n",
" <td>1.615920</td>\n",
" <td>1.662210</td>\n",
" <td>1.603296</td>\n",
" <td>1.662210</td>\n",
" <td>6892800</td>\n",
" <td>0.0</td>\n",
" <td>0.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Open High Low Close Volume Dividends \\\n",
"Date \n",
"2002-02-13 1.620128 1.693350 1.603296 1.691666 76216000 0.0 \n",
"2002-02-14 1.712707 1.716074 1.670626 1.683251 11021600 0.0 \n",
"2002-02-15 1.683251 1.687459 1.658002 1.674834 8389600 0.0 \n",
"2002-02-19 1.666417 1.666417 1.578047 1.607504 7410400 0.0 \n",
"2002-02-20 1.615920 1.662210 1.603296 1.662210 6892800 0.0 \n",
"\n",
" Stock Splits \n",
"Date \n",
"2002-02-13 0.0 \n",
"2002-02-14 0.0 \n",
"2002-02-15 0.0 \n",
"2002-02-19 0.0 \n",
"2002-02-20 0.0 "
]
},
"execution_count": 102,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gme_data.head()\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 4: Use Webscraping to Extract GME Revenue Data\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use the `requests` library to download the webpage <https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-PY0220EN-SkillsNetwork/labs/project/stock.html>. Save the text of the response as a variable named `html_data`.\n"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [],
"source": [
"url = \"https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBMDeveloperSkillsNetwork-PY0220EN-SkillsNetwork/labs/project/stock.html\"\n",
"\n",
"html_data = requests.get(url).text"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Parse the html data using `beautiful_soup`.\n"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [],
"source": [
"soup = BeautifulSoup(html_data)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using `BeautifulSoup` or the `read_html` function extract the table with `GameStop Quarterly Revenue` and store it into a dataframe named `gme_revenue`. The dataframe should have columns `Date` and `Revenue`. Make sure the comma and dollar sign is removed from the `Revenue` column using a method similar to what you did in Question 2.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<details><summary>Click here if you need help locating the table</summary>\n",
"\n",
"```\n",
" \n",
"Below is the code to isolate the table, you will now need to loop through the rows and columns like in the previous lab\n",
" \n",
"soup.find_all(\"tbody\")[1]\n",
" \n",
"If you want to use the read_html function the table is located at index 1\n",
"\n",
"\n",
"```\n",
"\n",
"</details>\n"
]
},
{
"cell_type": "code",
"execution_count": 85,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/jupyterlab/conda/envs/python/lib/python3.7/site-packages/ipykernel_launcher.py:13: FutureWarning:\n",
"\n",
"The default value of regex will change from True to False in a future version.\n",
"\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Date</th>\n",
" <th>Revenue</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2020</td>\n",
" <td>6466</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2019</td>\n",
" <td>8285</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2018</td>\n",
" <td>8547</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2017</td>\n",
" <td>7965</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2016</td>\n",
" <td>9364</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Date Revenue\n",
"0 2020 6466\n",
"1 2019 8285\n",
"2 2018 8547\n",
"3 2017 7965\n",
"4 2016 9364"
]
},
"execution_count": 85,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gme_revenue = pd.DataFrame(columns=[\"Date\", \"Revenue\"])\n",
"\n",
"# First we isolate the body of the table which contains all the information\n",
"# Then we loop through each row and find all the column values for each row\n",
"for row in soup.find(\"tbody\").find_all('tr'):\n",
" col = row.find_all(\"td\")\n",
" date = col[0].text\n",
" Revenue = col[1].text\n",
" \n",
" # Finally we append the data of each row to the table\n",
" gme_revenue = gme_revenue.append({\"Date\":date, \"Revenue\":Revenue}, ignore_index=True) \n",
" \n",
" gme_revenue[\"Revenue\"] = gme_revenue['Revenue'].str.replace(',|\\$',\"\")\n",
" \n",
" \n",
" \n",
" \n",
"gme_revenue.head() \n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Display the last five rows of the `gme_revenue` dataframe using the `tail` function. Take a screenshot of the results.\n"
]
},
{
"cell_type": "code",
"execution_count": 78,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Date</th>\n",
" <th>Revenue</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>2009</td>\n",
" <td>8806</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>2008</td>\n",
" <td>7094</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>2007</td>\n",
" <td>5319</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>2006</td>\n",
" <td>3092</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>2005</td>\n",
" <td>1843</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Date Revenue\n",
"11 2009 8806\n",
"12 2008 7094\n",
"13 2007 5319\n",
"14 2006 3092\n",
"15 2005 1843"
]
},
"execution_count": 78,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gme_revenue.tail()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 5: Plot Tesla Stock Graph\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use the `make_graph` function to graph the Tesla Stock Data, also provide a title for the graph. The structure to call the `make_graph` function is `make_graph(tesla_data, tesla_revenue, 'Tesla')`. Note the graph will only show data upto June 2021.\n"
]
},
{
"cell_type": "code",
"execution_count": 103,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'DataFrame' object has no attribute 'Date'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/tmp/ipykernel_68/1765937996.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmake_graph\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtesla_data\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtesla_revenue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"Tesla\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m/tmp/ipykernel_68/2068038883.py\u001b[0m in \u001b[0;36mmake_graph\u001b[0;34m(stock_data, revenue_data, stock)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmake_graph\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstock_data\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrevenue_data\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstock\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mfig\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmake_subplots\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrows\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcols\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mshared_xaxes\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msubplot_titles\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Historical Share Price\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"Historical Revenue\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvertical_spacing\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m.3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mstock_data_specific\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mstock_data\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstock_data\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDate\u001b[0m \u001b[0;34m<=\u001b[0m \u001b[0;34m'2021--06-14'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mrevenue_data_specific\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrevenue_data\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mrevenue_data\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDate\u001b[0m \u001b[0;34m<=\u001b[0m \u001b[0;34m'2021-04-30'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mfig\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd_trace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mScatter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_datetime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstock_data_specific\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minfer_datetime_format\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstock_data_specific\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mClose\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"float\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"Share Price\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrow\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcol\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/conda/envs/python/lib/python3.7/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 5485\u001b[0m ):\n\u001b[1;32m 5486\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 5487\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5488\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5489\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__setattr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mAttributeError\u001b[0m: 'DataFrame' object has no attribute 'Date'"
]
}
],
"source": [
"make_graph(tesla_data, tesla_revenue, \"Tesla\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question 6: Plot GameStop Stock Graph\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use the `make_graph` function to graph the GameStop Stock Data, also provide a title for the graph. The structure to call the `make_graph` function is `make_graph(gme_data, gme_revenue, 'GameStop')`. Note the graph will only show data upto June 2021.\n"
]
},
{
"cell_type": "code",
"execution_count": 104,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'DataFrame' object has no attribute 'Date'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m/tmp/ipykernel_68/2000178444.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mmake_graph\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgme_data\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgme_revenue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'GameStop'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m/tmp/ipykernel_68/2068038883.py\u001b[0m in \u001b[0;36mmake_graph\u001b[0;34m(stock_data, revenue_data, stock)\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmake_graph\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstock_data\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrevenue_data\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstock\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mfig\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmake_subplots\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrows\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcols\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mshared_xaxes\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msubplot_titles\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Historical Share Price\"\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m\"Historical Revenue\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvertical_spacing\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;36m.3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mstock_data_specific\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mstock_data\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mstock_data\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDate\u001b[0m \u001b[0;34m<=\u001b[0m \u001b[0;34m'2021--06-14'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0mrevenue_data_specific\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mrevenue_data\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mrevenue_data\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDate\u001b[0m \u001b[0;34m<=\u001b[0m \u001b[0;34m'2021-04-30'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mfig\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd_trace\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mgo\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mScatter\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mx\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_datetime\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstock_data_specific\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDate\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minfer_datetime_format\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0my\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mstock_data_specific\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mClose\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mastype\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"float\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"Share Price\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mrow\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcol\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/conda/envs/python/lib/python3.7/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 5485\u001b[0m ):\n\u001b[1;32m 5486\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 5487\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5488\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5489\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__setattr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mAttributeError\u001b[0m: 'DataFrame' object has no attribute 'Date'"
]
}
],
"source": [
"make_graph(gme_data, gme_revenue, 'GameStop')\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h2>About the Authors:</h2> \n",
"\n",
"<a href=\"https://www.linkedin.com/in/joseph-s-50398b136/?utm_medium=Exinfluencer&utm_source=Exinfluencer&utm_content=000026UJ&utm_term=10006555&utm_id=NA-SkillsNetwork-Channel-SkillsNetworkCoursesIBMDeveloperSkillsNetworkPY0220ENSkillsNetwork23455606-2022-01-01\">Joseph Santarcangelo</a> has a PhD in Electrical Engineering, his research focused on using machine learning, signal processing, and computer vision to determine how videos impact human cognition. Joseph has been working for IBM since he completed his PhD.\n",
"\n",
"Azim Hirjani\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Change Log\n",
"\n",
"| Date (YYYY-MM-DD) | Version | Changed By | Change Description |\n",
"| ----------------- | ------- | ------------- | --------------------------- |\n",
"| 2022-02-28 | 1.2 | Lakshmi Holla | Changed the URL of GameStop |\n",
"| 2020-11-10 | 1.1 | Malika Singla | Deleted the Optional part |\n",
"| 2020-08-27 | 1.0 | Malika Singla | Added lab to GitLab |\n",
"\n",
"<hr>\n",
"\n",
"## <h3 align=\"center\"> © IBM Corporation 2020. All rights reserved. <h3/>\n",
"\n",
"<p>\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python",
"language": "python",
"name": "conda-env-python-py"
},
"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.12"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment