{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Title :\n",
"\n",
"## Description :\n",
"The aim of this exercise is to **plot** TV Ads vs Sales based on the Advertisement dataset which should look similar to the graph given below.\n",
"\n",
"\n",
"\n",
"## Data Description:\n",
"\n",
"## Instructions:\n",
"- Read the Advertisement data and view the top rows of the dataframe to get an understanding of the data and the columns.\n",
"- Select the first 7 observations and the columns `TV` and `Sales` to make a new data frame.\n",
"- Create a scatter plot of the new data frame `TV` budget vs `Sales`.\n",
"\n",
"## Hints: \n",
"\n",
"pd.read_csv(filename)\n",
"Returns a pandas dataframe containing the data and labels from the file data\n",
"\n",
"df.iloc[]\n",
"Returns a subset of the dataframe that is contained in the row range passed as the argument\n",
"\n",
"np.linspace()\n",
"Returns evenly spaced numbers over a specified interval\n",
"\n",
"df.head()\n",
"Returns the first 5 rows of the dataframe with the column names\n",
"\n",
"plt.scatter()\n",
"A scatter plot of y vs. x with varying marker size and/or color\n",
"\n",
"plt.xlabel()\n",
"This is used to specify the text to be displayed as the label for the x-axis\n",
"\n",
"plt.ylabel()\n",
"This is used to specify the text to be displayed as the label for the y-axis\n",
"\n",
"\n",
"**Note:** This exercise is auto-graded and you can try multiple attempts."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Import necessary libraries\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Reading the Advertisement dataset"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# \"Advertising.csv\" containts the data set used in this exercise\n",
"data_filename = 'Advertising.csv'\n",
"\n",
"# Read the file \"Advertising.csv\" file using the pandas library\n",
"df = pd.read_csv(\"Advertising.csv\")\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n", " | TV | \n", "Radio | \n", "Newspaper | \n", "Sales | \n", "
---|---|---|---|---|
count | \n", "200.000000 | \n", "200.000000 | \n", "200.000000 | \n", "200.000000 | \n", "
mean | \n", "147.042500 | \n", "23.264000 | \n", "30.554000 | \n", "14.022500 | \n", "
std | \n", "85.854236 | \n", "14.846809 | \n", "21.778621 | \n", "5.217457 | \n", "
min | \n", "0.700000 | \n", "0.000000 | \n", "0.300000 | \n", "1.600000 | \n", "
25% | \n", "74.375000 | \n", "9.975000 | \n", "12.750000 | \n", "10.375000 | \n", "
50% | \n", "149.750000 | \n", "22.900000 | \n", "25.750000 | \n", "12.900000 | \n", "
75% | \n", "218.825000 | \n", "36.525000 | \n", "45.100000 | \n", "17.400000 | \n", "
max | \n", "296.400000 | \n", "49.600000 | \n", "114.000000 | \n", "27.000000 | \n", "