[go: up one dir, main page]

0% found this document useful (0 votes)
14 views53 pages

Data_Science_Cohort_1_Assignment_1.ipynb

Download as txt, pdf, or txt
Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1/ 53

{"cells":[{"cell_type":"markdown","metadata":{"id":"8b27UrEfZhbV"},"source":["<hr

style=\"border:5px solid #002060\"> </hr>"]},{"cell_type":"markdown","metadata":


{"id":"glI39JToZhbe"},"source":["# pandas Fundamentals <hr style=\"border:4.5px
solid #002060\"> </hr>"]},{"cell_type":"markdown","metadata":{"id":"OFHYbf-
FZhbg"},"source":["## Introduction to pandas Series"]},
{"cell_type":"markdown","metadata":{"id":"JPZ4H0sgZhbh"},"source":["Import the
'pandas' library to load it into the computer's memory, so that you can work with
it in this Notebook Document.\n","\n","<br/> *Note: Don't forget to use the widely-
accepted convention as well.*\n","\n","<br/> Remember that no matter how many times
you execute this code cell, the library will be imported only once in this
Document, and it will remain active."]},
{"cell_type":"code","execution_count":3,"metadata":
{"id":"syudX2VtZhbj","executionInfo":
{"status":"ok","timestamp":1733939678231,"user_tz":-300,"elapsed":684,"user":
{"displayName":"Almas Islam","userId":"05912423101588664233"}}},"outputs":
[],"source":["#import pandas library\n","import pandas as pd"]},
{"cell_type":"markdown","metadata":{"id":"FrJArml4Zhbl"},"source":["Create the
**employee_names** list."]},{"cell_type":"code","execution_count":4,"metadata":
{"id":"XTc6iEVTZhbm","colab":{"base_uri":"https://
localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733939684974,"user_tz":-300,"elapsed":510,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"a0e6c27b-b963-45b8-99da-
06649019a1bf"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["['Amy White', 'Jack Stewart', 'Richard Lauderdale', 'Sara
Johnson']"]},"metadata":{},"execution_count":4}],"source":["employee_names = ['Amy
White', 'Jack Stewart', 'Richard Lauderdale', 'Sara Johnson']\
n","employee_names"]},{"cell_type":"markdown","metadata":
{"id":"Hcq7rRfEZhbq"},"source":["Verify the **employee_names** object is a
list."]},{"cell_type":"code","execution_count":5,"metadata":
{"id":"WflwsMrbZhbs","colab":{"base_uri":"https://
localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733939689267,"user_tz":-300,"elapsed":501,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"8456838d-aa15-4382-fd99-
4a761f077a35"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["list"]},"metadata":{},"execution_count":5}],"source":["type(employee_names)"]},
{"cell_type":"markdown","source":["\"employee_names\" is a list
indeed."],"metadata":{"id":"2bRR79gtaOyt"}},{"cell_type":"markdown","metadata":
{"id":"ycl2F9f3Zhbt"},"source":["Create a pandas Series object containing the
elements from the **employee_names** list. Call it **employee_names_Series**."]},
{"cell_type":"code","execution_count":6,"metadata":{"id":"CbxpuVDeZhbu","colab":
{"base_uri":"https://localhost:8080/","height":210},"executionInfo":
{"status":"ok","timestamp":1733939692385,"user_tz":-300,"elapsed":13,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"d1570ad1-64f3-45a4-fea2-
6d6f3df74788"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["0
Amy White\n","1 Jack Stewart\n","2 Richard Lauderdale\n","3
Sara Johnson\n","dtype: object"],"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>0</th>\n","
</tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n","
<td>Amy White</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n","
<td>Jack Stewart</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n","
<td>Richard Lauderdale</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n","
<td>Sara Johnson</td>\n"," </tr>\n","
</tbody>\n","</table>\n","</div><br><label><b>dtype:</b>
object</label>"]},"metadata":{},"execution_count":6}],"source":
["employee_names_Series = pd.Series(employee_names)\n","employee_names_Series"]},
{"cell_type":"markdown","metadata":{"id":"JLRr98gNZhbu"},"source":["Confirm the
object is of the Series type."]},
{"cell_type":"code","execution_count":7,"metadata":{"id":"wxWydBUlZhbv","colab":
{"base_uri":"https://localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733939696915,"user_tz":-300,"elapsed":683,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"fe32d80a-8b69-4a96-efd3-
22e40d02dca1"},"outputs":[{"output_type":"stream","name":"stdout","text":["<class
'pandas.core.series.Series'>\n"]}],"source":
["print(type(employee_names_Series))"]},{"cell_type":"markdown","source":
["\"employee_names_Series\" is a pandas Series."],"metadata":
{"id":"NKeRCjQDaznd"}},{"cell_type":"markdown","metadata":
{"id":"zLVEW0NDZhbv"},"source":["Now, create a Series object directly. That is, not
from an existing list, but by using the following structure:\
n","**pd.Series([...])**\n","<br/>Let the elements of the Series object be the
following numbers: 5, 8, 3, and 10. Name the object **work_experience_yrs.**\n"]},
{"cell_type":"code","source":["work_experience_yrs = pd.Series([5,8,3,10])\
n","work_experience_yrs"],"metadata":{"colab":{"base_uri":"https://
localhost:8080/","height":210},"id":"mgNOlPb_bTmx","executionInfo":
{"status":"ok","timestamp":1733939700200,"user_tz":-300,"elapsed":514,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"b509f1f2-47f2-4609-e806-
e5155ae09dba"},"execution_count":8,"outputs":
[{"output_type":"execute_result","data":{"text/plain":["0 5\n","1 8\n","2
3\n","3 10\n","dtype: int64"],"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>0</th>\n","
</tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n","
<td>5</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>8</td>\
n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>3</td>\n"," </tr>\
n"," <tr>\n"," <th>3</th>\n"," <td>10</td>\n"," </tr>\n","
</tbody>\n","</table>\n","</div><br><label><b>dtype:</b>
int64</label>"]},"metadata":{},"execution_count":8}]},
{"cell_type":"markdown","metadata":{"id":"gR4suqdmZhbw"},"source":["Import the
'NumPy' package to load it into the computer's memory, so that you can work with it
in this Notebook Document."]},{"cell_type":"markdown","metadata":
{"id":"JYrtGXmqZhbx"},"source":["*Note: Don't forget to use the widely-accepted
convention as well.*"]},{"cell_type":"code","execution_count":9,"metadata":
{"id":"W9R7txzzZhbx","executionInfo":
{"status":"ok","timestamp":1733939704821,"user_tz":-300,"elapsed":551,"user":
{"displayName":"Almas Islam","userId":"05912423101588664233"}}},"outputs":
[],"source":["#Import numpy library\n","import numpy as np"]},
{"cell_type":"markdown","metadata":{"id":"XTBfqNRUZhby"},"source":["Execute the
code cell below to create the **array_1** NumPy array object."]},
{"cell_type":"code","execution_count":10,"metadata":{"id":"aEGwpC66Zhby","colab":
{"base_uri":"https://localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733939707742,"user_tz":-300,"elapsed":571,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"84a0ee24-aaef-4e89-cd09-
5ab032c76600"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["array([50, 53, 35, 43])"]},"metadata":{},"execution_count":10}],"source":
["array_age = np.array([50, 53, 35, 43])\n","array_age"]},
{"cell_type":"markdown","metadata":{"id":"rt6-GpTSZhbz"},"source":["Verify the type
of the **array_age** object:"]},
{"cell_type":"code","execution_count":11,"metadata":{"id":"z2905lVwZhbz","colab":
{"base_uri":"https://localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733939709482,"user_tz":-300,"elapsed":9,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"265956f7-a6b5-404c-9240-
5ff0a64092bf"},"outputs":[{"output_type":"stream","name":"stdout","text":["<class
'numpy.ndarray'>\n"]}],"source":["print(type(array_age))"]},
{"cell_type":"markdown","metadata":{"id":"s3p_jxZDZhb0"},"source":["Create a Series
object called **series_age** from the NumPy array object **array_age** you just
created."]},{"cell_type":"code","execution_count":12,"metadata":
{"id":"EAI0eV_kZhb0","colab":{"base_uri":"https://
localhost:8080/","height":210},"executionInfo":
{"status":"ok","timestamp":1733939712167,"user_tz":-300,"elapsed":528,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"bda51be6-ae05-487a-f31c-
f2886809e84f"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["0
50\n","1 53\n","2 35\n","3 43\n","dtype: int64"],"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>0</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n","
<th>0</th>\n"," <td>50</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\
n"," <td>53</td>\n"," </tr>\n","
<tr>\n"," <th>2</th>\n"," <td>35</td>\n"," </tr>\n"," <tr>\n","
<th>3</th>\n"," <td>43</td>\n"," </tr>\n","
</tbody>\n","</table>\n","</div><br><label><b>dtype:</b>
int64</label>"]},"metadata":{},"execution_count":12}],"source":["series_age =
pd.Series(array_age)\n","series_age"]},{"cell_type":"markdown","metadata":
{"id":"UU3xq9wsZhb0"},"source":["Check the type of the newly created object."]},
{"cell_type":"code","execution_count":13,"metadata":{"id":"a_CCyTbxZhb1","colab":
{"base_uri":"https://localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733939716459,"user_tz":-300,"elapsed":571,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"a7a1cd67-0e40-4675-a161-
90f61166800b"},"outputs":[{"output_type":"stream","name":"stdout","text":["<class
'pandas.core.series.Series'>\n"]}],"source":["print(type(series_age))"]},
{"cell_type":"markdown","metadata":{"id":"Vehr4E4DZhb1"},"source":["Use the
*print()* function to display the content of **series_age**."]},
{"cell_type":"code","execution_count":14,"metadata":{"id":"SZ1jDT9xZhb2","colab":
{"base_uri":"https://localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733939718732,"user_tz":-300,"elapsed":513,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"0d0ba424-3781-4944-dfcf-
b628cd7835f6"},"outputs":[{"output_type":"stream","name":"stdout","text":["0 50\
n","1 53\n","2 35\n","3 43\n","dtype: int64\n"]}],"source":
["print(series_age)"]},{"cell_type":"markdown","metadata":
{"id":"YLHXaX7VZhb2"},"source":["## Working with Methods in Python"]},
{"cell_type":"markdown","metadata":{"id":"AzRG2WnzZhb2"},"source":["Consider the
following Series object."]},{"cell_type":"code","execution_count":15,"metadata":
{"id":"qmI4jD_zZhb3","executionInfo":
{"status":"ok","timestamp":1733939722429,"user_tz":-300,"elapsed":808,"user":
{"displayName":"Almas Islam","userId":"05912423101588664233"}}},"outputs":
[],"source":["employees_work_exp = pd.Series({\n","'Amy White' : 3,\n","'Jack
Stewart' : 5,\n","'Richard Lauderdale' : 4.5,\n","'Sara Johnson' : 22,\
n","'Patrick Adams' : 28,\n","'Jessica Baker' : 14,\n","'Peter Hunt' : 4,\
n","'Daniel Lloyd' : 6,\n","'John Owen' : 1.5,\n","'Jennifer Phillips' : 10,\
n","'Courtney Rogers' : 4.5,\n","'Anne Robinson' : 2,\n","})"]},
{"cell_type":"code","source":["employees_work_exp"],"metadata":{"colab":
{"base_uri":"https://
localhost:8080/","height":460},"id":"2aLSCBEBe57H","executionInfo":
{"status":"ok","timestamp":1733939725472,"user_tz":-300,"elapsed":686,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"3ff0756c-8ee7-419e-b301-
31aed0f062c1"},"execution_count":16,"outputs":
[{"output_type":"execute_result","data":{"text/plain":["Amy White 3.0\
n","Jack Stewart 5.0\n","Richard Lauderdale 4.5\n","Sara Johnson
22.0\n","Patrick Adams 28.0\n","Jessica Baker 14.0\n","Peter Hunt
4.0\n","Daniel Lloyd 6.0\n","John Owen 1.5\n","Jennifer
Phillips 10.0\n","Courtney Rogers 4.5\n","Anne Robinson 2.0\
n","dtype: float64"],"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>0</th>\n","
</tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>Amy White</th>\n","
<td>3.0</td>\n"," </tr>\n"," <tr>\n"," <th>Jack Stewart</th>\n","
<td>5.0</td>\n"," </tr>\n"," <tr>\n"," <th>Richard Lauderdale</th>\n","
<td>4.5</td>\n"," </tr>\n"," <tr>\n"," <th>Sara Johnson</th>\n","
<td>22.0</td>\n"," </tr>\n"," <tr>\n"," <th>Patrick Adams</th>\n","
<td>28.0</td>\n"," </tr>\n"," <tr>\n"," <th>Jessica Baker</th>\n","
<td>14.0</td>\n"," </tr>\n"," <tr>\n"," <th>Peter Hunt</th>\n","
<td>4.0</td>\n"," </tr>\n"," <tr>\n"," <th>Daniel Lloyd</th>\n","
<td>6.0</td>\n"," </tr>\n"," <tr>\n"," <th>John Owen</th>\n","
<td>1.5</td>\n"," </tr>\n"," <tr>\n"," <th>Jennifer Phillips</th>\n","
<td>10.0</td>\n"," </tr>\n"," <tr>\n"," <th>Courtney Rogers</th>\n","
<td>4.5</td>\n"," </tr>\n"," <tr>\n"," <th>Anne Robinson</th>\n","
<td>2.0</td>\n"," </tr>\n","
</tbody>\n","</table>\n","</div><br><label><b>dtype:</b>
float64</label>"]},"metadata":{},"execution_count":16}]},
{"cell_type":"markdown","metadata":{"id":"u7LTU0j1Zhb3"},"source":["Use a certain
method to extract the top five values from this Series."]},
{"cell_type":"code","execution_count":17,"metadata":{"id":"PeUsQswkZhb4","colab":
{"base_uri":"https://localhost:8080/","height":241},"executionInfo":
{"status":"ok","timestamp":1733939729086,"user_tz":-300,"elapsed":516,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"9418cc82-61ce-4211-f619-
fb43a44b3ed0"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["Amy White 3.0\n","Jack Stewart 5.0\n","Richard Lauderdale
4.5\n","Sara Johnson 22.0\n","Patrick Adams 28.0\n","dtype:
float64"],"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>0</th>\n","
</tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>Amy White</th>\n","
<td>3.0</td>\n"," </tr>\n"," <tr>\n"," <th>Jack Stewart</th>\n","
<td>5.0</td>\n"," </tr>\n"," <tr>\n"," <th>Richard Lauderdale</th>\n","
<td>4.5</td>\n"," </tr>\n"," <tr>\n"," <th>Sara Johnson</th>\n","
<td>22.0</td>\n"," </tr>\n"," <tr>\n"," <th>Patrick Adams</th>\n","
<td>28.0</td>\n"," </tr>\n","
</tbody>\n","</table>\n","</div><br><label><b>dtype:</b>
float64</label>"]},"metadata":{},"execution_count":17}],"source":
["employees_work_exp.head()"]},{"cell_type":"markdown","metadata":{"id":"a4jD-
CyiZhb4"},"source":["Use another method to extract the last few rows of
**employees_work_exp**."]},{"cell_type":"code","source":
["employees_work_exp.tail()"],"metadata":{"colab":{"base_uri":"https://
localhost:8080/","height":241},"id":"_LCcQaqnfZ7Q","executionInfo":
{"status":"ok","timestamp":1733939732717,"user_tz":-300,"elapsed":569,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"fd5e099e-f417-4fda-9241-
94e1efc9661d"},"execution_count":18,"outputs":
[{"output_type":"execute_result","data":{"text/plain":["Daniel Lloyd 6.0\
n","John Owen 1.5\n","Jennifer Phillips 10.0\n","Courtney Rogers
4.5\n","Anne Robinson 2.0\n","dtype: float64"],"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>0</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n","
<th>Daniel Lloyd</th>\n"," <td>6.0</td>\n"," </tr>\n"," <tr>\n","
<th>John Owen</th>\n"," <td>1.5</td>\n"," </tr>\n"," <tr>\n","
<th>Jennifer Phillips</th>\n"," <td>10.0</td>\n"," </tr>\n"," <tr>\n","
<th>Courtney Rogers</th>\n"," <td>4.5</td>\n"," </tr>\n"," <tr>\n","
<th>Anne Robinson</th>\n"," <td>2.0</td>\n"," </tr>\n","
</tbody>\n","</table>\n","</div><br><label><b>dtype:</b>
float64</label>"]},"metadata":{},"execution_count":18}]},
{"cell_type":"markdown","metadata":{"id":"j68j3kZpZhb4"},"source":["##
Using .unique() and .nunique()"]},{"cell_type":"code","source":["from google.colab
import drive\n","drive.mount('/content/drive')"],"metadata":{"colab":
{"base_uri":"https://localhost:8080/"},"id":"hJpsDAlbgBN4","executionInfo":
{"status":"ok","timestamp":1733939769069,"user_tz":-300,"elapsed":33543,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"2cb357b2-cfec-4535-b524-
fcb82f370ce9"},"execution_count":19,"outputs":
[{"output_type":"stream","name":"stdout","text":["Mounted at /content/drive\n"]}]},
{"cell_type":"markdown","metadata":{"id":"XLv35wNRZhb5"},"source":["Load
the \"Region.csv\" file and use the .squeeze() method to convert it into a series.
Store the information in a variable called **region_data**. Preview the data with
the pandas *.head()* method."]},{"cell_type":"code","source":["region_data =
pd.read_csv(\"/content/drive/MyDrive/Region.csv\").squeeze()"],"metadata":
{"id":"czcOHstgh-C7","executionInfo":
{"status":"ok","timestamp":1733939772917,"user_tz":-300,"elapsed":1617,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}}},"execution_count":20,"outputs":[]},
{"cell_type":"markdown","metadata":{"id":"oLu2g9fkZhb5"},"source":["Verify that
**region_data** is a Series object."]},
{"cell_type":"code","execution_count":21,"metadata":{"collapsed":true,"jupyter":
{"outputs_hidden":true},"id":"x_grGCIhZhb6","colab":{"base_uri":"https://
localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733939776173,"user_tz":-300,"elapsed":658,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"cbf1c893-74c4-407e-b627-
0e80e6d558b7"},"outputs":[{"output_type":"stream","name":"stdout","text":["<class
'pandas.core.series.Series'>\n"]}],"source":["print(type(region_data))"]},
{"cell_type":"code","source":["region_data.head()"],"metadata":{"colab":
{"base_uri":"https://
localhost:8080/","height":241},"id":"nfId8Hemgs3y","executionInfo":
{"status":"ok","timestamp":1733939778204,"user_tz":-300,"elapsed":12,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"7a063b24-12cd-4f73-9ad6-
b825dd9d1736"},"execution_count":22,"outputs":
[{"output_type":"execute_result","data":{"text/plain":["0 Region 2\n","1
Region 6\n","2 Region 3\n","3 Region 2\n","4 Region 3\n","Name: Region,
dtype: object"],"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>Region</th>\
n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n","
<td>Region 2</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n","
<td>Region 6</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n","
<td>Region 3</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n","
<td>Region 2</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n","
<td>Region 3</td>\n"," </tr>\n","
</tbody>\n","</table>\n","</div><br><label><b>dtype:</b>
object</label>"]},"metadata":{},"execution_count":22}]},
{"cell_type":"markdown","metadata":{"id":"Qd1Ig_qUZhb6"},"source":["Use the
*.describe()* method to obtain descriptive statistics on the **region_data**
Series.\n","<br>Think of how many unique values there are in the data set.\
n","<br>*Please note that the statistics provided in the output exclude missing
data.*"]},{"cell_type":"code","execution_count":23,"metadata":
{"collapsed":true,"jupyter":{"outputs_hidden":true},"id":"b4IFBwM0ZhcE","colab":
{"base_uri":"https://localhost:8080/","height":210},"executionInfo":
{"status":"ok","timestamp":1733939782031,"user_tz":-300,"elapsed":521,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"ac34b6c3-eafb-4e6e-88ee-
3d60e5d0b19b"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["count 1042\n","unique 18\n","top Region 6\n","freq
326\n","Name: Region, dtype: object"],"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>Region</th>\
n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>count</th>\
n"," <td>1042</td>\n"," </tr>\n"," <tr>\n"," <th>unique</th>\n","
<td>18</td>\n"," </tr>\n"," <tr>\n"," <th>top</th>\n"," <td>Region
6</td>\n"," </tr>\n"," <tr>\n"," <th>freq</th>\n"," <td>326</td>\
n"," </tr>\n"," </tbody>\n","</table>\n","</div><br><label><b>dtype:</b>
object</label>"]},"metadata":{},"execution_count":23}],"source":
["region_data.describe()"]},{"cell_type":"markdown","metadata":
{"id":"Waa_QlGCZhcF"},"source":["You can obtain some of the values from the
previous output by using Python built-in functions or methods. Please extract the
total number of values from the **region_data** Series, then the number of unique
values. Finally, obtain a list containing all unique values from this Series."]},
{"cell_type":"code","source":["print(region_data.describe()[0])"],"metadata":
{"colab":{"base_uri":"https://
localhost:8080/"},"id":"T0INsJaUlbu5","executionInfo":
{"status":"ok","timestamp":1733939786192,"user_tz":-300,"elapsed":703,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"7cfa3618-0422-427e-ff1c-
9919717ad4e0"},"execution_count":24,"outputs":
[{"output_type":"stream","name":"stdout","text":["1042\n"]},
{"output_type":"stream","name":"stderr","text":["<ipython-input-24-4dcd1e510422>:1:
FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a
future version, integer keys will always be treated as labels (consistent with
DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n","
print(region_data.describe()[0])\n"]}]},
{"cell_type":"code","execution_count":25,"metadata":{"id":"Py0oQDSqZhcF","colab":
{"base_uri":"https://localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733939788504,"user_tz":-300,"elapsed":506,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"428536c6-c087-4f9b-b363-
be45627b51bf"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["1042"]},"metadata":{},"execution_count":25}],"source":
["region_data.value_counts().sum()"]},{"cell_type":"markdown","source":["There are
tital 1042 values in region_data."],"metadata":{"id":"m_gDUBLelxmM"}},
{"cell_type":"code","source":["region_data.unique()"],"metadata":{"colab":
{"base_uri":"https://localhost:8080/"},"id":"_I1kRUffhSSm","executionInfo":
{"status":"ok","timestamp":1733939791693,"user_tz":-300,"elapsed":513,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"564fb394-c696-45c7-8532-
6e85308ef0bd"},"execution_count":26,"outputs":
[{"output_type":"execute_result","data":{"text/plain":["array(['Region 2', 'Region
6', 'Region 3', 'Region 1', 'Region 5',\n"," 'Region 9', 'Region 7', 'Region
4', 'Region 12', 'Region 16',\n"," 'Region 8', 'Region 10', 'Region 13',
'Region 15', 'Region 11',\n"," 'Region 14', 'Region 17', 'Region 18'],
dtype=object)"]},"metadata":{},"execution_count":26}]},
{"cell_type":"markdown","metadata":{"id":"oE2ycMFvZhcG"},"source":["##
Using .sort_values()"]},{"cell_type":"markdown","metadata":
{"id":"E0gsqRThZhcG"},"source":["Sort the values without specifying any
arguments."]},{"cell_type":"markdown","metadata":{"id":"NaBycmh6ZhcG"},"source":
["*Please note that the numbers go from 1 to 18, but we are currently ordering the
values as labels, not integers. 1 is succeeded by 10, then 11, and so on until 18.
Then we have 2, 3, 4, etc., until 8, and eventually - 9.*"]},
{"cell_type":"code","execution_count":27,"metadata":{"id":"eo4vhaSnZhcH","colab":
{"base_uri":"https://localhost:8080/","height":458},"executionInfo":
{"status":"ok","timestamp":1733939796948,"user_tz":-300,"elapsed":510,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"dd8bd7c2-e74d-43c0-e2b4-
5c3a7e6417d3"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["462 Region 1\n","347 Region 1\n","609 Region 1\n","610 Region 1\
n","339 Region 1\n"," ... \n","536 Region 9\n","450 Region 9\
n","8 Region 9\n","842 Region 9\n","940 Region 9\n","Name: Region,
Length: 1042, dtype: object"],"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>Region</th>\
n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>462</th>\n","
<td>Region 1</td>\n"," </tr>\n"," <tr>\n"," <th>347</th>\n","
<td>Region 1</td>\n"," </tr>\n"," <tr>\n"," <th>609</th>\n","
<td>Region 1</td>\n"," </tr>\n"," <tr>\n"," <th>610</th>\n","
<td>Region 1</td>\n"," </tr>\n"," <tr>\n"," <th>339</th>\n","
<td>Region 1</td>\n"," </tr>\n"," <tr>\n"," <th>...</th>\n","
<td>...</td>\n"," </tr>\n"," <tr>\n"," <th>536</th>\n"," <td>Region
9</td>\n"," </tr>\n"," <tr>\n"," <th>450</th>\n"," <td>Region
9</td>\n"," </tr>\n"," <tr>\n"," <th>8</th>\n"," <td>Region 9</td>\
n"," </tr>\n"," <tr>\n"," <th>842</th>\n"," <td>Region 9</td>\n","
</tr>\n"," <tr>\n"," <th>940</th>\n"," <td>Region 9</td>\n","
</tr>\n"," </tbody>\n","</table>\n","<p>1042 rows × 1
columns</p>\n","</div><br><label><b>dtype:</b> object</label>"]},"metadata":
{},"execution_count":27}],"source":["region_data.sort_values()"]},
{"cell_type":"markdown","metadata":{"id":"qHXfajCiZhcH"},"source":["Sort the
values, setting the *ascending* parameter equal to *True*."]},
{"cell_type":"code","execution_count":28,"metadata":{"id":"wfRtQDvsZhcI","colab":
{"base_uri":"https://localhost:8080/","height":458},"executionInfo":
{"status":"ok","timestamp":1733939801882,"user_tz":-300,"elapsed":525,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"9cc4086a-4650-40dd-f5d6-
c765a7506e58"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["462 Region 1\n","347 Region 1\n","609 Region 1\n","610 Region 1\
n","339 Region 1\n"," ... \n","536 Region 9\n","450 Region 9\
n","8 Region 9\n","842 Region 9\n","940 Region 9\n","Name: Region,
Length: 1042, dtype: object"],"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>Region</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n","
<tr>\n"," <th>462</th>\n"," <td>Region 1</td>\n"," </tr>\n"," <tr>\
n"," <th>347</th>\n"," <td>Region 1</td>\n"," </tr>\n"," <tr>\n","
<th>609</th>\n"," <td>Region 1</td>\n"," </tr>\n"," <tr>\n","
<th>610</th>\n"," <td>Region 1</td>\n"," </tr>\n"," <tr>\n","
<th>339</th>\n"," <td>Region 1</td>\n"," </tr>\n"," <tr>\n","
<th>...</th>\n"," <td>...</td>\n"," </tr>\n"," <tr>\n","
<th>536</th>\n"," <td>Region 9</td>\n"," </tr>\n"," <tr>\n","
<th>450</th>\n"," <td>Region 9</td>\n"," </tr>\n"," <tr>\n","
<th>8</th>\n"," <td>Region 9</td>\n"," </tr>\n"," <tr>\n","
<th>842</th>\n"," <td>Region 9</td>\n"," </tr>\n"," <tr>\n","
<th>940</th>\n"," <td>Region 9</td>\n"," </tr>\n"," </tbody>\n","</table>\
n","<p>1042 rows × 1 columns</p>\n","</div><br><label><b>dtype:</b>
object</label>"]},"metadata":{},"execution_count":28}],"source":
["region_data.sort_values(ascending = True)"]},{"cell_type":"markdown","metadata":
{"id":"0BJHJSVXZhcI"},"source":["Sort the values in **region_data** in descending
order."]},{"cell_type":"code","execution_count":29,"metadata":
{"id":"_zVGSkrTZhcJ","colab":{"base_uri":"https://
localhost:8080/","height":458},"executionInfo":
{"status":"ok","timestamp":1733939811400,"user_tz":-300,"elapsed":659,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"c5c04b0c-dcfe-4617-e204-
94b246582142"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["450 Region 9\n","842 Region 9\n","141 Region 9\n","940 Region 9\n","8
Region 9\n"," ... \n","569 Region 1\n","892 Region 1\n","558
Region 1\n","557 Region 1\n","309 Region 1\n","Name: Region, Length: 1042,
dtype: object"],"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>Region</th>\
n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>450</th>\n","
<td>Region 9</td>\n"," </tr>\n"," <tr>\n"," <th>842</th>\n","
<td>Region 9</td>\n"," </tr>\n"," <tr>\n"," <th>141</th>\n","
<td>Region 9</td>\n"," </tr>\n"," <tr>\n"," <th>940</th>\n","
<td>Region 9</td>\n"," </tr>\n"," <tr>\n"," <th>8</th>\n","
<td>Region 9</td>\n"," </tr>\n"," <tr>\n"," <th>...</th>\n","
<td>...</td>\n"," </tr>\n"," <tr>\n"," <th>569</th>\n"," <td>Region
1</td>\n"," </tr>\n"," <tr>\n"," <th>892</th>\n"," <td>Region
1</td>\n"," </tr>\n"," <tr>\n"," <th>558</th>\n"," <td>Region
1</td>\n"," </tr>\n"," <tr>\n"," <th>557</th>\n"," <td>Region
1</td>\n"," </tr>\n"," <tr>\n"," <th>309</th>\n"," <td>Region
1</td>\n"," </tr>\n"," </tbody>\n","</table>\n","<p>1042 rows × 1 columns</p>\
n","</div><br><label><b>dtype:</b> object</label>"]},"metadata":
{},"execution_count":29}],"source":["region_data.sort_values(ascending = False)"]},
{"cell_type":"markdown","metadata":{"id":"NrTB5b-fZhcJ"},"source":["## Introduction
to pandas DataFrames"]},{"cell_type":"markdown","metadata":
{"id":"eRBWtbgrZhcK"},"source":["Import the pandas and numpy libraries by using the
relevant well-known conventions."]},
{"cell_type":"code","execution_count":30,"metadata":{"id":"d-
bs2Q5_ZhcL","executionInfo":{"status":"ok","timestamp":1733939815282,"user_tz":-
300,"elapsed":490,"user":{"displayName":"Almas
Islam","userId":"05912423101588664233"}}},"outputs":[],"source":["import pandas as
pd\n","import numpy as np"]},{"cell_type":"markdown","metadata":
{"id":"5j2O2ABMZhcM"},"source":["The goal of this exercise is to solidify your
knowledge and understanding of the fundamentals of using pandas DataFrames."]},
{"cell_type":"markdown","metadata":{"id":"oufd_QlXZhcM"},"source":["Execute the
next code cell to create the array called **array_c**."]},
{"cell_type":"code","execution_count":31,"metadata":{"id":"DvwbbIiqZhcN","colab":
{"base_uri":"https://localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733939817938,"user_tz":-300,"elapsed":538,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"f9bfc601-2826-430f-892d-
0853a0163597"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["array([[1000. , 50. , 78.45],\n"," [ 700. , 112. ,
35.5 ]])"]},"metadata":{},"execution_count":31}],"source":["array_c =
np.array([[1000, 50, 78.45], [700, 112, 35.5]])\n","array_c"]},
{"cell_type":"markdown","metadata":{"id":"uA90pKkNZhcO"},"source":["Convert
**array_c** into a DataFrame, called **company_statistics**. Assign the column
names and row labels from the following lists as column names and index of this
DataFrame, respectively."]},{"cell_type":"code","execution_count":32,"metadata":
{"id":"Laq1sy8gZhcO","executionInfo":
{"status":"ok","timestamp":1733939820940,"user_tz":-300,"elapsed":512,"user":
{"displayName":"Almas Islam","userId":"05912423101588664233"}}},"outputs":
[],"source":["# column names\n","columns = ['No. of Employees', 'Avg. Annual
Revenue ($)', 'Share price ($)']"]},
{"cell_type":"code","execution_count":33,"metadata":
{"id":"j6yL1iChZhcO","executionInfo":
{"status":"ok","timestamp":1733939822454,"user_tz":-300,"elapsed":6,"user":
{"displayName":"Almas Islam","userId":"05912423101588664233"}}},"outputs":
[],"source":["# row labels\n","labels = ['Company A', 'Company B']"]},
{"cell_type":"code","source":["company_statistics = pd.DataFrame(array_c,columns =
columns,index= labels)"],"metadata":{"id":"CP270ky2ozpW","executionInfo":
{"status":"ok","timestamp":1733939825133,"user_tz":-300,"elapsed":5,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}}},"execution_count":34,"outputs":[]},
{"cell_type":"markdown","metadata":{"id":"xPsTznc-ZhcP"},"source":["Display the
**company_statistics** DataFrame."]},
{"cell_type":"code","execution_count":35,"metadata":{"id":"H3EgcdF8ZhcP","colab":
{"base_uri":"https://localhost:8080/","height":219},"executionInfo":
{"status":"ok","timestamp":1733939828943,"user_tz":-300,"elapsed":547,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"262b0fb2-4c59-4c74-8c89-
2b460ca53c4d"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["
No. of Employees Avg. Annual Revenue ($) Share price ($)\n","Company A
1000.0 50.0 78.45\n","Company B 700.0
112.0 35.50"],"text/html":["\n"," <div id=\"df-9538141e-9e63-4b59-8092-
a4a4c0dee1fe\" class=\"colab-df-container\">\n"," <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>No. of
Employees</th>\n"," <th>Avg. Annual Revenue ($)</th>\n"," <th>Share price
($)</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n","
<th>Company A</th>\n"," <td>1000.0</td>\n"," <td>50.0</td>\n","
<td>78.45</td>\n"," </tr>\n"," <tr>\n"," <th>Company B</th>\n","
<td>700.0</td>\n"," <td>112.0</td>\n"," <td>35.50</td>\n"," </tr>\n","
</tbody>\n","</table>\n","</div>\n"," <div class=\"colab-df-buttons\">\n","\n","
<div class=\"colab-df-container\">\n"," <button class=\"colab-df-convert\"
onclick=\"convertToInteractive('df-9538141e-9e63-4b59-8092-a4a4c0dee1fe')\"\n","
title=\"Convert this dataframe to an interactive table.\"\n","
style=\"display:none;\">\n","\n"," <svg xmlns=\"http://www.w3.org/2000/svg\"
height=\"24px\" viewBox=\"0 -960 960 960\">\n"," <path d=\"M120-120v-
720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-
160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-
160H180v160Zm440 0h160v-160H620v160Z\"/>\n"," </svg>\n"," </button>\n","\n","
<style>\n"," .colab-df-container {\n"," display:flex;\n"," gap: 12px;\
n"," }\n","\n"," .colab-df-convert {\n"," background-color: #E8F0FE;\
n"," border: none;\n"," border-radius: 50%;\n"," cursor: pointer;\
n"," display: none;\n"," fill: #1967D2;\n"," height: 32px;\n","
padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-
convert:hover {\n"," background-color: #E2EBFA;\n"," box-shadow: 0px 1px
2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill:
#174EA6;\n"," }\n","\n"," .colab-df-buttons div {\n"," margin-bottom:
4px;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n"," background-
color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n","
[theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n","
box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px
1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\
n","\n"," <script>\n"," const buttonEl =\n","
document.querySelector('#df-9538141e-9e63-4b59-8092-a4a4c0dee1fe button.colab-df-
convert');\n"," buttonEl.style.display =\n","
google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function
convertToInteractive(key) {\n"," const element =
document.querySelector('#df-9538141e-9e63-4b59-8092-a4a4c0dee1fe');\n","
const dataTable =\n"," await
google.colab.kernel.invokeFunction('convertToInteractive',\n","
[key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml
= 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\"
href=https://colab.research.google.com/notebooks/data_table.ipynb>data table
notebook</a>'\n"," + ' to learn more about interactive tables.';\n","
element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n","
await google.colab.output.renderOutput(dataTable, element);\n"," const
docLink = document.createElement('div');\n"," docLink.innerHTML =
docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n","
</script>\n"," </div>\n","\n","\n","<div id=\"df-24b18c6d-d669-47c3-9d32-
6eac0f3a4436\">\n"," <button class=\"colab-df-quickchart\"
onclick=\"quickchart('df-24b18c6d-d669-47c3-9d32-6eac0f3a4436')\"\n","
title=\"Suggest charts\"\n"," style=\"display:none;\">\n","\n","<svg
xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n","
width=\"24px\">\n"," <g>\n"," <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0
1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-
2v-4h2v4z\"/>\n"," </g>\n","</svg>\n"," </button>\n","\n","<style>\
n"," .colab-df-quickchart {\n"," --bg-color: #E8F0FE;\n"," --fill-color:
#1967D2;\n"," --hover-bg-color: #E2EBFA;\n"," --hover-fill-color:
#174EA6;\n"," --disabled-fill-color: #AAA;\n"," --disabled-bg-color:
#DDD;\n"," }\n","\n"," [theme=dark] .colab-df-quickchart {\n"," --bg-color:
#3B4455;\n"," --fill-color: #D2E3FC;\n"," --hover-bg-color: #434B5C;\n","
--hover-fill-color: #FFFFFF;\n"," --disabled-bg-color: #3B4455;\n"," --
disabled-fill-color: #666;\n"," }\n","\n"," .colab-df-quickchart {\n","
background-color: var(--bg-color);\n"," border: none;\n"," border-radius:
50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: var(--fill-
color);\n"," height: 32px;\n"," padding: 0;\n"," width: 32px;\n"," }\
n","\n"," .colab-df-quickchart:hover {\n"," background-color: var(--hover-bg-
color);\n"," box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60,
64, 67, 0.15);\n"," fill: var(--button-hover-fill-color);\n"," }\n","\
n"," .colab-df-quickchart-complete:disabled,\n"," .colab-df-quickchart-
complete:disabled:hover {\n"," background-color: var(--disabled-bg-color);\n","
fill: var(--disabled-fill-color);\n"," box-shadow: none;\n"," }\n","\
n"," .colab-df-spinner {\n"," border: 2px solid var(--fill-color);\n","
border-color: transparent;\n"," border-bottom-color: var(--fill-color);\n","
animation:\n"," spin 1s steps(1) infinite;\n"," }\n","\n"," @keyframes spin
{\n"," 0% {\n"," border-color: transparent;\n"," border-bottom-color:
var(--fill-color);\n"," border-left-color: var(--fill-color);\n"," }\n","
20% {\n"," border-color: transparent;\n"," border-left-color: var(--fill-
color);\n"," border-top-color: var(--fill-color);\n"," }\n"," 30% {\n","
border-color: transparent;\n"," border-left-color: var(--fill-color);\n","
border-top-color: var(--fill-color);\n"," border-right-color: var(--fill-
color);\n"," }\n"," 40% {\n"," border-color: transparent;\n","
border-right-color: var(--fill-color);\n"," border-top-color: var(--fill-
color);\n"," }\n"," 60% {\n"," border-color: transparent;\n","
border-right-color: var(--fill-color);\n"," }\n"," 80% {\n"," border-
color: transparent;\n"," border-right-color: var(--fill-color);\n","
border-bottom-color: var(--fill-color);\n"," }\n"," 90% {\n"," border-
color: transparent;\n"," border-bottom-color: var(--fill-color);\n"," }\
n"," }\n","</style>\n","\n"," <script>\n"," async function quickchart(key) {\
n"," const quickchartButtonEl =\n"," document.querySelector('#' + key +
' button');\n"," quickchartButtonEl.disabled = true; // To prevent multiple
clicks.\n"," quickchartButtonEl.classList.add('colab-df-spinner');\n","
try {\n"," const charts = await google.colab.kernel.invokeFunction(\n","
'suggestCharts', [key], {});\n"," } catch (error) {\n","
console.error('Error during call to suggestCharts:', error);\n"," }\n","
quickchartButtonEl.classList.remove('colab-df-spinner');\n","
quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n"," }\n","
(() => {\n"," let quickchartButtonEl =\n","
document.querySelector('#df-24b18c6d-d669-47c3-9d32-6eac0f3a4436 button');\n","
quickchartButtonEl.style.display =\n"," google.colab.kernel.accessAllowed ?
'block' : 'none';\n"," })();\n"," </script>\n","</div>\n","\n"," <div
id=\"id_e1edc603-39fb-4741-b5a3-96c9bb1b06eb\">\n"," <style>\n"," .colab-
df-generate {\n"," background-color: #E8F0FE;\n"," border: none;\n","
border-radius: 50%;\n"," cursor: pointer;\n"," display: none;\n","
fill: #1967D2;\n"," height: 32px;\n"," padding: 0 0 0 0;\n","
width: 32px;\n"," }\n","\n"," .colab-df-generate:hover {\n","
background-color: #E2EBFA;\n"," box-shadow: 0px 1px 2px rgba(60, 64, 67,
0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill: #174EA6;\
n"," }\n","\n"," [theme=dark] .colab-df-generate {\n","
background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n","
[theme=dark] .colab-df-generate:hover {\n"," background-color: #434B5C;\n","
box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-
shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n","
</style>\n"," <button class=\"colab-df-generate\"
onclick=\"generateWithVariable('company_statistics')\"\n","
title=\"Generate code using this dataframe.\"\n","
style=\"display:none;\">\n","\n"," <svg xmlns=\"http://www.w3.org/2000/svg\"
height=\"24px\"viewBox=\"0 0 24 24\"\n"," width=\"24px\">\n"," <path
d=\"M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.
43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-
12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.3
1,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12
Z\"/>\n"," </svg>\n"," </button>\n"," <script>\n"," (() => {\n","
const buttonEl =\n"," document.querySelector('#id_e1edc603-39fb-4741-b5a3-
96c9bb1b06eb button.colab-df-generate');\n"," buttonEl.style.display =\n","
google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n","
buttonEl.onclick = () => {\n","
google.colab.notebook.generateWithVariable('company_statistics');\n"," }\n","
})();\n"," </script>\n"," </div>\n","\n"," </div>\n"," </div>\
n"],"application/vnd.google.colaboratory.intrinsic+json":
{"type":"dataframe","variable_name":"company_statistics","summary":"{\
n \"name\": \"company_statistics\",\n \"rows\": 2,\n \"fields\": [\n {\n
\"column\": \"No. of Employees\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 212.13203435596427,\
n \"min\": 700.0,\n \"max\": 1000.0,\n \"num_unique_values\":
2,\n \"samples\": [\n 700.0,\n 1000.0\n ],\n
\"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n
\"column\": \"Avg. Annual Revenue ($)\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 43.840620433565945,\
n \"min\": 50.0,\n \"max\": 112.0,\n \"num_unique_values\":
2,\n \"samples\": [\n 112.0,\n 50.0\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Share price ($)\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 30.37023625196222,\
n \"min\": 35.5,\n \"max\": 78.45,\n \"num_unique_values\":
2,\n \"samples\": [\n 35.5,\n 78.45\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n
]\n}"}},"metadata":{},"execution_count":35}],"source":["company_statistics"]},
{"cell_type":"code","execution_count":null,"metadata":
{"id":"ULmUXLgSZhcQ"},"outputs":[],"source":[]},{"cell_type":"markdown","metadata":
{"id":"X9Y8RGVAZhcQ"},"source":["Import the *Sales-products.csv* dataset into a
DataFrame object called **sales_products_data**."]},
{"cell_type":"markdown","metadata":{"id":"9M2wNguTZhcR"},"source":["*Note: Please
use the default index provided for this DataFrame throughout this exercise.*"]},
{"cell_type":"code","execution_count":36,"metadata":{"id":"9GHHgOL_ZhcS","colab":
{"base_uri":"https://localhost:8080/","height":669},"executionInfo":
{"status":"ok","timestamp":1733939842750,"user_tz":-300,"elapsed":1007,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"77cfeabe-53e1-44f2-b7cb-
7bf02da1f9be"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["
SaleID RetailerCountry OrderMethod RetailerType \\\n","0 SaleID_1
United States
Fax Outdoors Shop \n","1 SaleID_2 United States Fax
Outdoors Shop \n","2 SaleID_3 United States Fax Outdoors Shop
\n","3 SaleID_4 United States Fax Outdoors Shop \n","4
SaleID_5 United States NaN Outdoors Shop \n","... ...
... ... ... \n","1271 SaleID_1272 Spain Sales
visit Outdoors Shop \n","1272 SaleID_1273 Spain Sales visit
Outdoors Shop \n","1273 SaleID_1274 Spain Sales visit Outdoors Shop
\n","1274 SaleID_1275 Spain Sales visit Outdoors Shop \n","1275
SaleID_1276 Spain Sales visit Outdoors Shop \n","\n","
ProductLine ProductType Product \\\n","0 Personal
Accessories Cooking Gear TrailChef Deluxe Cook Set \n","1
Sports Equipment Cooking Gear TrailChef Double Flame \n","2
NaN Tents Star Dome \n","3
NaN Tents Star Gazer 2 \n","4 Personal
Accessories First Aid Compact Relief Kit \n","...
... ... ... \n","1271 Personal
Accessories Rope Husky Rope 60 \n","1272 Outdoor
Protection Climbing Accessories Firefly Climbing Lamp \n","1273 Personal
Accessories Climbing Accessories Firefly Charger \n","1274 Personal
Accessories Tools Granite Axe \n","1275
Camping Equipment Tools Granite Extreme \n","\n","
Year Quarter Revenue Quantity GrossMargin \n","0 2018.0 Q1 2018
59728.66 491.0 0.357548 \n","1 2018.0 Q1 2018 36050.32 254.0
0.484274 \n","2 2018.0 Q1 2018 90040.48 149.0 NaN \n","3
2018.0 Q1 2018 NaN 305.0 0.292938 \n","4 2018.0 Q1 2018
NaN 182.0 0.610710 \n","... ... ... ... ...
... \n","1271 2020.0 Q3 2020 30916.50 173.0 0.298114 \n","1272 2020.0
Q3 2020 7536.29 193.0 0.445287 \n","1273 2020.0 Q3 2020 12306.48
238.0 0.568420 \n","1274 2020.0 Q3 2020 56499.00 1472.0 0.490667 \
n","1275 2020.0 Q3 2020 89427.00 1178.0 0.386895 \n","\n","[1276 rows x
12 columns]"],"text/html":["\n"," <div id=\"df-a0bfaeaa-4e85-4425-9efc-
6bfaa7fa6008\" class=\"colab-df-container\">\n"," <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>SaleID</th>\
n"," <th>RetailerCountry</th>\n"," <th>OrderMethod</th>\n","
<th>RetailerType</th>\n"," <th>ProductLine</th>\n","
<th>ProductType</th>\n"," <th>Product</th>\n"," <th>Year</th>\n","
<th>Quarter</th>\n"," <th>Revenue</th>\n"," <th>Quantity</th>\n","
<th>GrossMargin</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n","
<th>0</th>\n"," <td>SaleID_1</td>\n"," <td>United States</td>\n","
<td>Fax</td>\n"," <td>Outdoors Shop</td>\n"," <td>Personal
Accessories</td>\n"," <td>Cooking Gear</td>\n"," <td>TrailChef Deluxe
Cook Set</td>\n"," <td>2018.0</td>\n"," <td>Q1 2018</td>\n","
<td>59728.66</td>\n"," <td>491.0</td>\n"," <td>0.357548</td>\n","
</tr>\n"," <tr>\n"," <th>1</th>\n"," <td>SaleID_2</td>\n","
<td>United States</td>\n"," <td>Fax</td>\n"," <td>Outdoors Shop</td>\n","
<td>Sports Equipment</td>\n"," <td>Cooking Gear</td>\n"," <td>TrailChef
Double Flame</td>\n"," <td>2018.0</td>\n"," <td>Q1 2018</td>\n","
<td>36050.32</td>\n"," <td>254.0</td>\n"," <td>0.484274</td>\n","
</tr>\n"," <tr>\n"," <th>2</th>\n"," <td>SaleID_3</td>\n","
<td>United States</td>\n"," <td>Fax</td>\n"," <td>Outdoors Shop</td>\n","
<td>NaN</td>\n"," <td>Tents</td>\n"," <td>Star Dome</td>\n","
<td>2018.0</td>\n"," <td>Q1 2018</td>\n"," <td>90040.48</td>\n","
<td>149.0</td>\n"," <td>NaN</td>\n"," </tr>\n"," <tr>\n","
<th>3</th>\n"," <td>SaleID_4</td>\n"," <td>United States</td>\n","
<td>Fax</td>\n"," <td>Outdoors Shop</td>\n"," <td>NaN</td>\n","
<td>Tents</td>\n"," <td>Star Gazer 2</td>\n"," <td>2018.0</td>\n","
<td>Q1 2018</td>\n"," <td>NaN</td>\n"," <td>305.0</td>\n","
<td>0.292938</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n","
<td>SaleID_5</td>\n"," <td>United States</td>\n"," <td>NaN</td>\n","
<td>Outdoors Shop</td>\n"," <td>Personal Accessories</td>\n"," <td>First
Aid</td>\n"," <td>Compact Relief Kit</td>\n"," <td>2018.0</td>\n","
<td>Q1 2018</td>\n"," <td>NaN</td>\n"," <td>182.0</td>\n","
<td>0.610710</td>\n"," </tr>\n"," <tr>\n"," <th>...</th>\n","
<td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\
n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n","
<td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\
n"," <td>...</td>\n"," </tr>\n"," <tr>\n"," <th>1271</th>\n","
<td>SaleID_1272</td>\n"," <td>Spain</td>\n"," <td>Sales visit</td>\n","
<td>Outdoors Shop</td>\n"," <td>Personal Accessories</td>\n","
<td>Rope</td>\n"," <td>Husky Rope 60</td>\n"," <td>2020.0</td>\n","
<td>Q3 2020</td>\n"," <td>30916.50</td>\n"," <td>173.0</td>\n","
<td>0.298114</td>\n"," </tr>\n"," <tr>\n"," <th>1272</th>\n","
<td>SaleID_1273</td>\n"," <td>Spain</td>\n"," <td>Sales visit</td>\n","
<td>Outdoors Shop</td>\n"," <td>Outdoor Protection</td>\n"," <td>Climbing
Accessories</td>\n"," <td>Firefly Climbing Lamp</td>\n","
<td>2020.0</td>\n"," <td>Q3 2020</td>\n"," <td>7536.29</td>\n","
<td>193.0</td>\n"," <td>0.445287</td>\n"," </tr>\n"," <tr>\n","
<th>1273</th>\n"," <td>SaleID_1274</td>\n"," <td>Spain</td>\n","
<td>Sales visit</td>\n"," <td>Outdoors Shop</td>\n"," <td>Personal
Accessories</td>\n"," <td>Climbing Accessories</td>\n"," <td>Firefly
Charger</td>\n"," <td>2020.0</td>\n"," <td>Q3 2020</td>\n","
<td>12306.48</td>\n"," <td>238.0</td>\n"," <td>0.568420</td>\n","
</tr>\n"," <tr>\n"," <th>1274</th>\n"," <td>SaleID_1275</td>\n","
<td>Spain</td>\n"," <td>Sales visit</td>\n"," <td>Outdoors Shop</td>\n","
<td>Personal Accessories</td>\n"," <td>Tools</td>\n"," <td>Granite
Axe</td>\n"," <td>2020.0</td>\n"," <td>Q3 2020</td>\n","
<td>56499.00</td>\n"," <td>1472.0</td>\n"," <td>0.490667</td>\n","
</tr>\n"," <tr>\n"," <th>1275</th>\n"," <td>SaleID_1276</td>\n","
<td>Spain</td>\n"," <td>Sales visit</td>\n"," <td>Outdoors Shop</td>\n","
<td>Camping Equipment</td>\n"," <td>Tools</td>\n"," <td>Granite
Extreme</td>\n"," <td>2020.0</td>\n"," <td>Q3 2020</td>\n","
<td>89427.00</td>\n"," <td>1178.0</td>\n"," <td>0.386895</td>\n","
</tr>\n"," </tbody>\n","</table>\n","<p>1276 rows × 12 columns</p>\n","</div>\n","
<div class=\"colab-df-buttons\">\n","\n"," <div class=\"colab-df-container\">\n","
<button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-a0bfaeaa-
4e85-4425-9efc-6bfaa7fa6008')\"\n"," title=\"Convert this dataframe to
an interactive table.\"\n"," style=\"display:none;\">\n","\n"," <svg
xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\
n"," <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-
160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-
160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n"," </svg>\
n"," </button>\n","\n"," <style>\n"," .colab-df-container {\n","
display:flex;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n","
background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\
n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n","
height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\
n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n","
box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67,
0.15);\n"," fill: #174EA6;\n"," }\n","\n"," .colab-df-buttons div {\n","
margin-bottom: 4px;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n","
background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n","
[theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n","
box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px
1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\
n","\n"," <script>\n"," const buttonEl =\n","
document.querySelector('#df-a0bfaeaa-4e85-4425-9efc-6bfaa7fa6008 button.colab-df-
convert');\n"," buttonEl.style.display =\n","
google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function
convertToInteractive(key) {\n"," const element =
document.querySelector('#df-a0bfaeaa-4e85-4425-9efc-6bfaa7fa6008');\n","
const dataTable =\n"," await
google.colab.kernel.invokeFunction('convertToInteractive',\n","
[key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml
= 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\"
href=https://colab.research.google.com/notebooks/data_table.ipynb>data table
notebook</a>'\n"," + ' to learn more about interactive tables.';\n","
element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n","
await google.colab.output.renderOutput(dataTable, element);\n"," const
docLink = document.createElement('div');\n"," docLink.innerHTML =
docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n","
</script>\n"," </div>\n","\n","\n","<div id=\"df-670d99a5-ba7a-41c6-a23f-
8bd45d3db74e\">\n"," <button class=\"colab-df-quickchart\"
onclick=\"quickchart('df-670d99a5-ba7a-41c6-a23f-8bd45d3db74e')\"\n","
title=\"Suggest charts\"\n"," style=\"display:none;\">\n","\n","<svg
xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n","
width=\"24px\">\n"," <g>\n"," <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0
1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-
2v-4h2v4z\"/>\n"," </g>\n","</svg>\n"," </button>\n","\n","<style>\
n"," .colab-df-quickchart {\n"," --bg-color: #E8F0FE;\n"," --fill-color:
#1967D2;\n"," --hover-bg-color: #E2EBFA;\n"," --hover-fill-color:
#174EA6;\n"," --disabled-fill-color: #AAA;\n"," --disabled-bg-color:
#DDD;\n"," }\n","\n"," [theme=dark] .colab-df-quickchart {\n"," --bg-color:
#3B4455;\n"," --fill-color: #D2E3FC;\n"," --hover-bg-color: #434B5C;\n","
--hover-fill-color: #FFFFFF;\n"," --disabled-bg-color: #3B4455;\n"," --
disabled-fill-color: #666;\n"," }\n","\n"," .colab-df-quickchart {\n","
background-color: var(--bg-color);\n"," border: none;\n"," border-radius:
50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: var(--fill-
color);\n"," height: 32px;\n"," padding: 0;\n"," width: 32px;\n"," }\
n","\n"," .colab-df-quickchart:hover {\n"," background-color: var(--hover-bg-
color);\n"," box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60,
64, 67, 0.15);\n"," fill: var(--button-hover-fill-color);\n"," }\n","\
n"," .colab-df-quickchart-complete:disabled,\n"," .colab-df-quickchart-
complete:disabled:hover {\n"," background-color: var(--disabled-bg-color);\n","
fill: var(--disabled-fill-color);\n"," box-shadow: none;\n"," }\n","\
n"," .colab-df-spinner {\n"," border: 2px solid var(--fill-color);\n","
border-color: transparent;\n"," border-bottom-color: var(--fill-color);\n","
animation:\n"," spin 1s steps(1) infinite;\n"," }\n","\n"," @keyframes spin
{\n"," 0% {\n"," border-color: transparent;\n"," border-bottom-color:
var(--fill-color);\n"," border-left-color: var(--fill-color);\n"," }\n","
20% {\n"," border-color: transparent;\n"," border-left-color: var(--fill-
color);\n"," border-top-color: var(--fill-color);\n"," }\n"," 30% {\n","
border-color: transparent;\n"," border-left-color: var(--fill-color);\n","
border-top-color: var(--fill-color);\n"," border-right-color: var(--fill-
color);\n"," }\n"," 40% {\n"," border-color: transparent;\n","
border-right-color: var(--fill-color);\n"," border-top-color: var(--fill-
color);\n"," }\n"," 60% {\n"," border-color: transparent;\n","
border-right-color: var(--fill-color);\n"," }\n"," 80% {\n"," border-
color: transparent;\n"," border-right-color: var(--fill-color);\n","
border-bottom-color: var(--fill-color);\n"," }\n"," 90% {\n"," border-
color: transparent;\n"," border-bottom-color: var(--fill-color);\n"," }\
n"," }\n","</style>\n","\n"," <script>\n"," async function quickchart(key) {\
n"," const quickchartButtonEl =\n"," document.querySelector('#' + key +
' button');\n"," quickchartButtonEl.disabled = true; // To prevent multiple
clicks.\n"," quickchartButtonEl.classList.add('colab-df-spinner');\n","
try {\n"," const charts = await google.colab.kernel.invokeFunction(\n","
'suggestCharts', [key], {});\n"," } catch (error) {\n","
console.error('Error during call to suggestCharts:', error);\n"," }\n","
quickchartButtonEl.classList.remove('colab-df-spinner');\n","
quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n"," }\n","
(() => {\n"," let quickchartButtonEl =\n","
document.querySelector('#df-670d99a5-ba7a-41c6-a23f-8bd45d3db74e button');\n","
quickchartButtonEl.style.display =\n"," google.colab.kernel.accessAllowed ?
'block' : 'none';\n"," })();\n"," </script>\n","</div>\n","\n"," <div
id=\"id_3300135e-07a9-4a19-9e47-93fc513c6406\">\n"," <style>\n"," .colab-
df-generate {\n"," background-color: #E8F0FE;\n"," border: none;\n","
border-radius: 50%;\n"," cursor: pointer;\n"," display: none;\n","
fill: #1967D2;\n"," height: 32px;\n"," padding: 0 0 0 0;\n","
width: 32px;\n"," }\n","\n"," .colab-df-generate:hover {\n","
background-color: #E2EBFA;\n"," box-shadow: 0px 1px 2px rgba(60, 64, 67,
0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill: #174EA6;\
n"," }\n","\n"," [theme=dark] .colab-df-generate {\n","
background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n","
[theme=dark] .colab-df-generate:hover {\n"," background-color: #434B5C;\n","
box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-
shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n","
</style>\n"," <button class=\"colab-df-generate\"
onclick=\"generateWithVariable('sales_products_data')\"\n","
title=\"Generate code using this dataframe.\"\n","
style=\"display:none;\">\n","\n"," <svg xmlns=\"http://www.w3.org/2000/svg\"
height=\"24px\"viewBox=\"0 0 24 24\"\n"," width=\"24px\">\n"," <path
d=\"M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.
43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-
12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.3
1,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12
Z\"/>\n"," </svg>\n"," </button>\n"," <script>\n"," (() => {\n","
const buttonEl =\n"," document.querySelector('#id_3300135e-07a9-4a19-9e47-
93fc513c6406 button.colab-df-generate');\n"," buttonEl.style.display =\n","
google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n","
buttonEl.onclick = () => {\n","
google.colab.notebook.generateWithVariable('sales_products_data');\n"," }\n","
})();\n"," </script>\n"," </div>\n","\n"," </div>\n"," </div>\
n"],"application/vnd.google.colaboratory.intrinsic+json":
{"type":"dataframe","variable_name":"sales_products_data","summary":"{\n \"name\":
\"sales_products_data\",\n \"rows\": 1276,\n \"fields\": [\n {\
n \"column\": \"SaleID\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1276,\
n \"samples\": [\n \"SaleID_102\",\n \"SaleID_52\",\n
\"SaleID_77\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"RetailerCountry\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 21,\
n \"samples\": [\n \"United States\",\n \"Germany\",\n
\"Finland\"\n ],\n \"semantic_type\": \"\",\n \"description\":
\"\"\n }\n },\n {\n \"column\": \"OrderMethod\",\
n \"properties\": {\n \"dtype\": \"category\",\
n \"num_unique_values\": 7,\n \"samples\": [\n \"Fax\",\n
\"Phone\",\n \"Other\"\n ],\n \"semantic_type\": \"\",\n
\"description\": \"\"\n }\n },\n {\n \"column\": \"RetailerType\",\
n \"properties\": {\n \"dtype\": \"category\",\
n \"num_unique_values\": 8,\n \"samples\": [\n \"Mall\",\n
\"Discount Retailer\",\n \"Outdoors Shop\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"ProductLine\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 5,\
n \"samples\": [\n \"Sports Equipment\",\n \"Outdoor
Protection\",\n \"Camping Equipment\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"ProductType\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 21,\
n \"samples\": [\n \"Cooking Gear\",\n \"Putters\",\n
\"Navigation\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Product\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 143,\
n \"samples\": [\n \"Star Gazer 6\",\n \"Granite Climbing
Helmet\",\n \"EverGlow Lamp\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Year\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 0.7175962927121285,\
n \"min\": 2018.0,\n
\"max\": 2020.0,\n \"num_unique_values\": 3,\n \"samples\":
[\n 2018.0,\n 2019.0,\n 2020.0\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Quarter\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 10,\
n \"samples\": [\n \"Q2 2020\",\n \"Q2 2018\",\
n \"Q3 2019\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Revenue\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 51124.45062498806,\
n \"min\": 0.0,\n \"max\": 944436.75,\n \"num_unique_values\":
1241,\n \"samples\": [\n 12754.32,\n 36648.64,\n
5680.05\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Quantity\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 977.7235161907016,\
n \"min\": 1.0,\n \"max\": 13758.0,\n \"num_unique_values\":
723,\n \"samples\": [\n 251.0,\n 358.0,\n 3556.0\
n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n
}\n },\n {\n \"column\": \"GrossMargin\",\n \"properties\": {\n
\"dtype\": \"number\",\n \"std\": 0.11257501207480596,\n \"min\":
0.05870851,\n \"max\": 0.78047619,\n \"num_unique_values\": 691,\n
\"samples\": [\n 0.49066667,\n 0.48346215,\n 0.64469388\
n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n
}\n }\n ]\n}"}},"metadata":{},"execution_count":36}],"source":
["sales_products_data = pd.read_csv(\"/content/drive/MyDrive/Sales-products.csv\")\
n","sales_products_data"]},{"cell_type":"markdown","metadata":
{"id":"TvpTbU3yZhcS"},"source":["Verify that the obtained object is a pandas
DataFrame."]},{"cell_type":"code","execution_count":37,"metadata":
{"id":"C1EQbxKpZhcT","colab":{"base_uri":"https://
localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733939847978,"user_tz":-300,"elapsed":660,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"d7fd91c3-608c-4d58-af90-
7e4597e05101"},"outputs":[{"output_type":"stream","name":"stdout","text":["<class
'pandas.core.frame.DataFrame'>\n"]}],"source":
["print(type(sales_products_data))"]},{"cell_type":"markdown","metadata":
{"id":"koKSL7hYZhcT"},"source":["Try out a well-known pandas method used for Series
on this DataFrame to obtain its last five rows."]},
{"cell_type":"code","execution_count":38,"metadata":{"id":"OFEtGG6pZhcU","colab":
{"base_uri":"https://localhost:8080/","height":330},"executionInfo":
{"status":"ok","timestamp":1733939852982,"user_tz":-300,"elapsed":539,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"88811b1c-e2d1-4464-e6ca-
d59372a425e8"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["
SaleID RetailerCountry OrderMethod RetailerType \\\n","1271 SaleID_1272
Spain Sales visit Outdoors Shop \n","1272 SaleID_1273 Spain Sales
visit Outdoors Shop \n","1273 SaleID_1274 Spain Sales visit
Outdoors Shop \n","1274 SaleID_1275 Spain Sales visit Outdoors Shop
\n","1275 SaleID_1276 Spain Sales visit Outdoors Shop \n","\n","
ProductLine ProductType Product \\\n","1271 Personal
Accessories Rope Husky Rope 60 \n","1272 Outdoor
Protection Climbing Accessories Firefly Climbing Lamp \n","1273 Personal
Accessories Climbing Accessories Firefly Charger \n","1274 Personal
Accessories Tools Granite Axe \n","1275 Camping
Equipment Tools Granite Extreme \n","\n"," Year
Quarter Revenue Quantity GrossMargin \n","1271 2020.0 Q3 2020 30916.50
173.0 0.298114 \n","1272 2020.0 Q3 2020 7536.29 193.0 0.445287 \
n","1273 2020.0 Q3 2020 12306.48 238.0 0.568420 \n","1274 2020.0 Q3
2020 56499.00 1472.0 0.490667 \n","1275 2020.0 Q3 2020 89427.00
1178.0 0.386895 "],"text/html":["\n"," <div id=\"df-78c6c603-87fb-4509-9e93-
60ee33d6f080\" class=\"colab-df-container\">\n"," <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>SaleID</th>\
n"," <th>RetailerCountry</th>\n"," <th>OrderMethod</th>\n","
<th>RetailerType</th>\n"," <th>ProductLine</th>\n","
<th>ProductType</th>\n"," <th>Product</th>\n"," <th>Year</th>\n","
<th>Quarter</th>\n"," <th>Revenue</th>\n"," <th>Quantity</th>\n","
<th>GrossMargin</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n","
<th>1271</th>\n"," <td>SaleID_1272</td>\n"," <td>Spain</td>\n","
<td>Sales visit</td>\n"," <td>Outdoors Shop</td>\n"," <td>Personal
Accessories</td>\n"," <td>Rope</td>\n"," <td>Husky Rope 60</td>\n","
<td>2020.0</td>\n"," <td>Q3 2020</td>\n"," <td>30916.50</td>\n","
<td>173.0</td>\n"," <td>0.298114</td>\n"," </tr>\n"," <tr>\n","
<th>1272</th>\n"," <td>SaleID_1273</td>\n"," <td>Spain</td>\n","
<td>Sales visit</td>\n"," <td>Outdoors Shop</td>\n"," <td>Outdoor
Protection</td>\n"," <td>Climbing Accessories</td>\n"," <td>Firefly
Climbing Lamp</td>\n"," <td>2020.0</td>\n"," <td>Q3 2020</td>\n","
<td>7536.29</td>\n"," <td>193.0</td>\n"," <td>0.445287</td>\n","
</tr>\n"," <tr>\n"," <th>1273</th>\n"," <td>SaleID_1274</td>\n","
<td>Spain</td>\n"," <td>Sales visit</td>\n"," <td>Outdoors Shop</td>\n","
<td>Personal Accessories</td>\n"," <td>Climbing Accessories</td>\n","
<td>Firefly Charger</td>\n"," <td>2020.0</td>\n"," <td>Q3 2020</td>\n","
<td>12306.48</td>\n"," <td>238.0</td>\n"," <td>0.568420</td>\n","
</tr>\n"," <tr>\n"," <th>1274</th>\n"," <td>SaleID_1275</td>\n","
<td>Spain</td>\n"," <td>Sales visit</td>\n"," <td>Outdoors Shop</td>\n","
<td>Personal Accessories</td>\n"," <td>Tools</td>\n"," <td>Granite
Axe</td>\n"," <td>2020.0</td>\n"," <td>Q3 2020</td>\n","
<td>56499.00</td>\n"," <td>1472.0</td>\n"," <td>0.490667</td>\n","
</tr>\n"," <tr>\n"," <th>1275</th>\n"," <td>SaleID_1276</td>\n","
<td>Spain</td>\n"," <td>Sales visit</td>\n"," <td>Outdoors Shop</td>\n","
<td>Camping Equipment</td>\n"," <td>Tools</td>\n"," <td>Granite
Extreme</td>\n"," <td>2020.0</td>\n"," <td>Q3 2020</td>\n","
<td>89427.00</td>\n"," <td>1178.0</td>\n"," <td>0.386895</td>\n","
</tr>\n"," </tbody>\n","</table>\n","</div>\n"," <div class=\"colab-df-
buttons\">\n","\n"," <div class=\"colab-df-container\">\n"," <button
class=\"colab-df-convert\" onclick=\"convertToInteractive('df-78c6c603-87fb-4509-
9e93-60ee33d6f080')\"\n"," title=\"Convert this dataframe to an
interactive table.\"\n"," style=\"display:none;\">\n","\n"," <svg
xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\
n"," <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-
160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-
160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n"," </svg>\
n"," </button>\n","\n"," <style>\n"," .colab-df-container {\n","
display:flex;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n","
background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\
n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n","
height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\
n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n","
box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67,
0.15);\n"," fill: #174EA6;\n"," }\n","\n"," .colab-df-buttons div {\n","
margin-bottom: 4px;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n","
background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n","
[theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n","
box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px
1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\
n","\n"," <script>\n"," const buttonEl =\n","
document.querySelector('#df-78c6c603-87fb-4509-9e93-60ee33d6f080 button.colab-df-
convert');\n"," buttonEl.style.display =\n","
google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function
convertToInteractive(key) {\n"," const element =
document.querySelector('#df-78c6c603-87fb-4509-9e93-60ee33d6f080');\n","
const dataTable =\n"," await
google.colab.kernel.invokeFunction('convertToInteractive',\n","
[key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml
= 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\"
href=https://colab.research.google.com/notebooks/data_table.ipynb>data
table notebook</a>'\n"," + ' to learn more about interactive tables.';\
n"," element.innerHTML = '';\n"," dataTable['output_type'] =
'display_data';\n"," await google.colab.output.renderOutput(dataTable,
element);\n"," const docLink = document.createElement('div');\n","
docLink.innerHTML = docLinkHtml;\n"," element.appendChild(docLink);\n","
}\n"," </script>\n"," </div>\n","\n","\n","<div id=\"df-cebce991-5557-49f5-
b59f-0ffc52b0c46f\">\n"," <button class=\"colab-df-quickchart\"
onclick=\"quickchart('df-cebce991-5557-49f5-b59f-0ffc52b0c46f')\"\n","
title=\"Suggest charts\"\n"," style=\"display:none;\">\n","\n","<svg
xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n","
width=\"24px\">\n"," <g>\n"," <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0
1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-
2v-4h2v4z\"/>\n"," </g>\n","</svg>\n"," </button>\n","\n","<style>\
n"," .colab-df-quickchart {\n"," --bg-color: #E8F0FE;\n"," --fill-color:
#1967D2;\n"," --hover-bg-color: #E2EBFA;\n"," --hover-fill-color:
#174EA6;\n"," --disabled-fill-color: #AAA;\n"," --disabled-bg-color:
#DDD;\n"," }\n","\n"," [theme=dark] .colab-df-quickchart {\n"," --bg-color:
#3B4455;\n"," --fill-color: #D2E3FC;\n"," --hover-bg-color: #434B5C;\n","
--hover-fill-color: #FFFFFF;\n"," --disabled-bg-color: #3B4455;\n"," --
disabled-fill-color: #666;\n"," }\n","\n"," .colab-df-quickchart {\n","
background-color: var(--bg-color);\n"," border: none;\n"," border-radius:
50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: var(--fill-
color);\n"," height: 32px;\n"," padding: 0;\n"," width: 32px;\n"," }\
n","\n"," .colab-df-quickchart:hover {\n"," background-color: var(--hover-bg-
color);\n"," box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60,
64, 67, 0.15);\n"," fill: var(--button-hover-fill-color);\n"," }\n","\
n"," .colab-df-quickchart-complete:disabled,\n"," .colab-df-quickchart-
complete:disabled:hover {\n"," background-color: var(--disabled-bg-color);\n","
fill: var(--disabled-fill-color);\n"," box-shadow: none;\n"," }\n","\
n"," .colab-df-spinner {\n"," border: 2px solid var(--fill-color);\n","
border-color: transparent;\n"," border-bottom-color: var(--fill-color);\n","
animation:\n"," spin 1s steps(1) infinite;\n"," }\n","\n"," @keyframes spin
{\n"," 0% {\n"," border-color: transparent;\n"," border-bottom-color:
var(--fill-color);\n"," border-left-color: var(--fill-color);\n"," }\n","
20% {\n"," border-color: transparent;\n"," border-left-color: var(--fill-
color);\n"," border-top-color: var(--fill-color);\n"," }\n"," 30% {\n","
border-color: transparent;\n"," border-left-color: var(--fill-color);\n","
border-top-color: var(--fill-color);\n"," border-right-color: var(--fill-
color);\n"," }\n"," 40% {\n"," border-color: transparent;\n","
border-right-color: var(--fill-color);\n"," border-top-color: var(--fill-
color);\n"," }\n"," 60% {\n"," border-color: transparent;\n","
border-right-color: var(--fill-color);\n"," }\n"," 80% {\n"," border-
color: transparent;\n"," border-right-color: var(--fill-color);\n","
border-bottom-color: var(--fill-color);\n"," }\n"," 90% {\n"," border-
color: transparent;\n"," border-bottom-color: var(--fill-color);\n"," }\
n"," }\n","</style>\n","\n"," <script>\n"," async function quickchart(key) {\
n"," const quickchartButtonEl =\n"," document.querySelector('#' + key +
' button');\n"," quickchartButtonEl.disabled = true; // To prevent multiple
clicks.\n"," quickchartButtonEl.classList.add('colab-df-spinner');\n","
try {\n"," const charts = await google.colab.kernel.invokeFunction(\n","
'suggestCharts', [key], {});\n"," } catch (error) {\n","
console.error('Error during call to suggestCharts:', error);\n"," }\n","
quickchartButtonEl.classList.remove('colab-df-spinner');\n","
quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n"," }\n","
(() => {\n"," let quickchartButtonEl =\n","
document.querySelector('#df-cebce991-5557-49f5-b59f-0ffc52b0c46f button');\n","
quickchartButtonEl.style.display =\n"," google.colab.kernel.accessAllowed ?
'block' : 'none';\n"," })();\n"," </script>\n","</div>\n","\n"," </div>\n","
</div>\n"],"application/vnd.google.colaboratory.intrinsic+json":
{"type":"dataframe","summary":"{\n \"name\": \"sales_products_data\",\n \"rows\":
5,\n \"fields\": [\n {\n \"column\": \"SaleID\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 5,\
n \"samples\": [\n \"SaleID_1273\",\n \"SaleID_1276\",\n
\"SaleID_1274\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"RetailerCountry\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Spain\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"OrderMethod\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Sales visit\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"RetailerType\",\n \"properties\": {\n \"dtype\":
\"category\",\n \"num_unique_values\": 1,\n \"samples\": [\n
\"Outdoors Shop\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"ProductLine\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 3,\
n \"samples\": [\n \"Personal Accessories\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"ProductType\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 3,\
n \"samples\": [\n \"Rope\"\n ],\n \"semantic_type\":
\"\",\n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Product\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 5,\
n \"samples\": [\n \"Firefly Climbing Lamp\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Year\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 0.0,\n \"min\": 2020.0,\n
\"max\": 2020.0,\n \"num_unique_values\": 1,\n \"samples\": [\n
2020.0\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Quarter\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Q3 2020\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Revenue\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 33971.97864494324,\
n \"min\": 7536.29,\n \"max\": 89427.0,\
n \"num_unique_values\": 5,\n \"samples\": [\n 7536.29\n
],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\
n },\n {\n \"column\": \"Quantity\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 624.6172427975392,\
n \"min\": 173.0,\n \"max\": 1472.0,\n \"num_unique_values\":
5,\n \"samples\": [\n 193.0\n ],\n \"semantic_type\":
\"\",\n \"description\": \"\"\n }\n },\n {\
n \"column\": \"GrossMargin\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 0.10248931743254383,\
n \"min\": 0.29811357,\n \"max\": 0.56842037,\
n \"num_unique_values\": 5,\n \"samples\": [\n 0.44528732\n
],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\
n }\n ]\n}"}},"metadata":{},"execution_count":38}],"source":
["sales_products_data.tail()"]},
{"cell_type":"code","execution_count":null,"metadata":
{"id":"Vk8dHyMwZhcU"},"outputs":[],"source":[]},{"cell_type":"markdown","metadata":
{"id":"2fF73XwTZhcU"},"source":["## pandas DataFrames - Common Attributes"]},
{"cell_type":"markdown","metadata":{"id":"kLf6q8ADZhcV"},"source":["Import the
*Sales-products.csv* dataset into a DataFrame object called
**sales_products_data**."]},{"cell_type":"markdown","metadata":
{"id":"CqsE665oZhcV"},"source":["*Note: Please use the default index provided for
this DataFrame throughout this exercise.*"]},{"cell_type":"markdown","metadata":
{"id":"7YWzfRkqZhcW"},"source":["Return the index of the **sales_products_data**
DataFrame."]},{"cell_type":"code","execution_count":39,"metadata":
{"id":"Nv5udq9eZhcW","colab":{"base_uri":"https://
localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733939858813,"user_tz":-300,"elapsed":504,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"85a744e9-3049-4538-ae98-
514f779efbbd"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["RangeIndex(start=0, stop=1276, step=1)"]},"metadata":
{},"execution_count":39}],"source":["sales_products_data.index"]},
{"cell_type":"markdown","metadata":{"id":"xsbh69UxZhcW"},"source":["Verify that
**sales_products_data**
is a RangeIndex object in an alternative way by using the **type()** funciton."]},
{"cell_type":"code","execution_count":40,"metadata":{"id":"Ol4WNOZeZhcX","colab":
{"base_uri":"https://localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733939860947,"user_tz":-300,"elapsed":509,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"e612c4d0-fec7-43aa-9cc0-
c548446ac9d5"},"outputs":[{"output_type":"stream","name":"stdout","text":["<class
'pandas.core.indexes.range.RangeIndex'>\n"]}],"source":
["print(type(sales_products_data.index))"]},{"cell_type":"markdown","metadata":
{"id":"nETwPj_HZhcX"},"source":["Retrieve and Index object containing all column
names from the **sales_products_data** DataFrame."]},
{"cell_type":"code","execution_count":41,"metadata":
{"scrolled":true,"id":"Ht2lcx7cZhcY","colab":{"base_uri":"https://
localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733939863653,"user_tz":-300,"elapsed":524,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"55390b7e-37e5-4b85-8735-
a8a9cf5796ee"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["Index(['SaleID', 'RetailerCountry', 'OrderMethod', 'RetailerType',\n","
'ProductLine', 'ProductType', 'Product', 'Year', 'Quarter', 'Revenue',\n","
'Quantity', 'GrossMargin'],\n"," dtype='object')"]},"metadata":
{},"execution_count":41}],"source":["columns = sales_products_data.columns\
n","columns"]},{"cell_type":"markdown","metadata":{"id":"IZXRcB4qZhcY"},"source":
["You are requested to create a new DataFrame, called **df**, whose data is
obtained from the the names of the columns of **sales_products_data** DataFrame,
while the column names are obtained from the **new_column_names**
list.\n","<br/><br/> First, execute the next cell to create **new_column_names**,
and then in the next cell try creating the **df** DataFrame yourself (by helping
yourself with the newly created **new_column_names** list).\n","<br/><br/> *Note:
There are two ways to achieve this - one would be through utilizing the*
**columns** *parameter, and the other – with the help of the* **\"columns\"**
*attribute. Choose whichever option you prefer (or why not try both!).*"]},
{"cell_type":"code","execution_count":42,"metadata":{"id":"yDZ-Rjn-
ZhcZ","executionInfo":{"status":"ok","timestamp":1733939868120,"user_tz":-
300,"elapsed":635,"user":{"displayName":"Almas
Islam","userId":"05912423101588664233"}}},"outputs":[],"source":["new_column_names
= ['SaleID', 'Country', 'OrderMethod', 'Retailer', 'Line',\n"," 'Type',
'Product', 'YearOfSales', 'Quarter', 'Revenue', 'Quantity',\n","
'Margin']"]},{"cell_type":"code","execution_count":45,"metadata":
{"id":"sjCP6EiFZhcb","executionInfo":
{"status":"ok","timestamp":1733940127051,"user_tz":-300,"elapsed":497,"user":
{"displayName":"Almas Islam","userId":"05912423101588664233"}}},"outputs":
[],"source":["\n","df = pd.DataFrame(data = [sales_products_data.columns],columns =
new_column_names)"]},{"cell_type":"code","execution_count":46,"metadata":
{"id":"4PBqJexcZhcb","colab":{"base_uri":"https://
localhost:8080/","height":109},"executionInfo":
{"status":"ok","timestamp":1733940132940,"user_tz":-300,"elapsed":644,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"11bb6295-dd55-443a-b947-
c6dbef60280b"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["
SaleID Country OrderMethod Retailer Line \\\n","0 SaleID
RetailerCountry OrderMethod RetailerType ProductLine \n","\n"," Type
Product YearOfSales Quarter Revenue Quantity Margin \n","0 ProductType
Product Year Quarter Revenue Quantity GrossMargin "],"text/html":["\
n"," <div id=\"df-7a085522-89d5-4ef2-ad34-da43a857b45d\" class=\"colab-df-
container\">\n"," <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>SaleID</th>\n"," <th>Country</th>\
n"," <th>OrderMethod</th>\n"," <th>Retailer</th>\n"," <th>Line</th>\
n"," <th>Type</th>\n"," <th>Product</th>\n"," <th>YearOfSales</th>\
n"," <th>Quarter</th>\n"," <th>Revenue</th>\n"," <th>Quantity</th>\
n"," <th>Margin</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\
n"," <th>0</th>\n"," <td>SaleID</td>\n"," <td>RetailerCountry</td>\
n"," <td>OrderMethod</td>\n"," <td>RetailerType</td>\n","
<td>ProductLine</td>\n"," <td>ProductType</td>\n"," <td>Product</td>\n","
<td>Year</td>\n"," <td>Quarter</td>\n"," <td>Revenue</td>\n","
<td>Quantity</td>\n"," <td>GrossMargin</td>\n"," </tr>\n"," </tbody>\
n","</table>\n","</div>\n"," <div class=\"colab-df-buttons\">\n","\n"," <div
class=\"colab-df-container\">\n"," <button class=\"colab-df-convert\"
onclick=\"convertToInteractive('df-7a085522-89d5-4ef2-ad34-da43a857b45d')\"\n","
title=\"Convert this dataframe to an interactive table.\"\n","
style=\"display:none;\">\n","\n"," <svg xmlns=\"http://www.w3.org/2000/svg\"
height=\"24px\" viewBox=\"0 -960 960 960\">\n"," <path d=\"M120-120v-
720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-
160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-
160H180v160Zm440 0h160v-160H620v160Z\"/>\n"," </svg>\n"," </button>\n","\n","
<style>\n"," .colab-df-container {\n"," display:flex;\n"," gap: 12px;\
n"," }\n","\n"," .colab-df-convert {\n"," background-color: #E8F0FE;\
n"," border: none;\n"," border-radius: 50%;\n"," cursor: pointer;\
n"," display: none;\n"," fill: #1967D2;\n"," height: 32px;\n","
padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-
convert:hover {\n"," background-color: #E2EBFA;\n"," box-shadow: 0px 1px
2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill:
#174EA6;\n"," }\n","\n"," .colab-df-buttons div {\n"," margin-bottom:
4px;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n"," background-
color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n","
[theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n","
box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px
1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\
n","\n"," <script>\n"," const buttonEl =\n","
document.querySelector('#df-7a085522-89d5-4ef2-ad34-da43a857b45d button.colab-df-
convert');\n"," buttonEl.style.display =\n","
google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function
convertToInteractive(key) {\n"," const element =
document.querySelector('#df-7a085522-89d5-4ef2-ad34-da43a857b45d');\n","
const dataTable =\n"," await
google.colab.kernel.invokeFunction('convertToInteractive',\n","
[key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml
= 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\"
href=https://colab.research.google.com/notebooks/data_table.ipynb>data table
notebook</a>'\n"," + ' to learn more about interactive tables.';\n","
element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n","
await google.colab.output.renderOutput(dataTable, element);\n"," const
docLink = document.createElement('div');\n"," docLink.innerHTML =
docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n","
</script>\n"," </div>\n","\n","\n"," <div id=\"id_c99b9afc-1f7e-43aa-ba85-
802f04ae3fbf\">\n"," <style>\n"," .colab-df-generate {\n","
background-color: #E8F0FE;\n"," border: none;\n"," border-radius:
50%;\n"," cursor: pointer;\n"," display: none;\n"," fill:
#1967D2;\n"," height: 32px;\n"," padding: 0 0 0 0;\n"," width:
32px;\n"," }\n","\n"," .colab-df-generate:hover {\n"," background-
color: #E2EBFA;\n"," box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px
3px 1px rgba(60, 64, 67, 0.15);\n"," fill: #174EA6;\n"," }\n","\n","
[theme=dark] .colab-df-generate {\n"," background-color: #3B4455;\n","
fill: #D2E3FC;\n"," }\n","\n"," [theme=dark] .colab-df-generate:hover {\
n"," background-color: #434B5C;\n"," box-shadow: 0px 1px 3px 1px
rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px 1px 2px rgba(0, 0, 0,
0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\n"," <button
class=\"colab-df-generate\" onclick=\"generateWithVariable('df')\"\n","
title=\"Generate code using this dataframe.\"\n","
style=\"display:none;\">\n","\n"," <svg xmlns=\"http://www.w3.org/2000/svg\"
height=\"24px\"viewBox=\"0 0 24 24\"\n"," width=\"24px\">\n"," <path
d=\"M7,19H8.4L18.45,9,17,7.55,7,17.6ZM5,21V16.75L18.45,3.32a2,2,0,0,1,2.83,0l1.4,1.
43a1.91,1.91,0,0,1,.58,1.4,1.91,1.91,0,0,1-.58,1.4L9.25,21ZM18.45,9,17,7.55Zm-
12,3A5.31,5.31,0,0,0,4.9,8.1,5.31,5.31,0,0,0,1,6.5,5.31,5.31,0,0,0,4.9,4.9,5.31,5.3
1,0,0,0,6.5,1,5.31,5.31,0,0,0,8.1,4.9,5.31,5.31,0,0,0,12,6.5,5.46,5.46,0,0,0,6.5,12
Z\"/>\n"," </svg>\n"," </button>\n"," <script>\n"," (() => {\n","
const buttonEl =\n"," document.querySelector('#id_c99b9afc-1f7e-43aa-ba85-
802f04ae3fbf button.colab-df-generate');\n"," buttonEl.style.display
=\n"," google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n","
buttonEl.onclick = () => {\n","
google.colab.notebook.generateWithVariable('df');\n"," }\n"," })();\n","
</script>\n"," </div>\n","\n"," </div>\n","
</div>\n"],"application/vnd.google.colaboratory.intrinsic+json":
{"type":"dataframe","variable_name":"df","summary":"{\n \"name\": \"df\",\
n \"rows\": 1,\n \"fields\": [\n {\n \"column\": \"SaleID\",\
n \"properties\": {\n \"dtype\": \"string\",\
n \"num_unique_values\": 1,\n \"samples\": [\n \"SaleID\"\n
],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\
n },\n {\n \"column\": \"Country\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"RetailerCountry\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"OrderMethod\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"OrderMethod\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Retailer\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"RetailerType\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Line\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"ProductLine\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Type\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"ProductType\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Product\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Product\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"YearOfSales\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Year\"\n ],\n \"semantic_type\":
\"\",\n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Quarter\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Quarter\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Revenue\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Revenue\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Quantity\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Quantity\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Margin\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"GrossMargin\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n
]\n}"}},"metadata":{},"execution_count":46}],"source":["df"]},
{"cell_type":"markdown","metadata":{"id":"HsrFMRmPZhcb"},"source":["Display
the \"head\" of the **df** DataFrame."]},
{"cell_type":"code","execution_count":47,"metadata":{"id":"Px1o9FcbZhcc","colab":
{"base_uri":"https://localhost:8080/","height":101},"executionInfo":
{"status":"ok","timestamp":1733940190299,"user_tz":-300,"elapsed":600,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"15b87899-d071-49f8-ed81-
372a58c79642"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["
SaleID Country OrderMethod Retailer Line \\\n","0 SaleID
RetailerCountry OrderMethod RetailerType ProductLine \n","\n"," Type
Product YearOfSales Quarter Revenue Quantity Margin \n","0 ProductType
Product Year Quarter Revenue Quantity GrossMargin "],"text/html":["\
n"," <div id=\"df-86e06034-ae8c-4319-898c-53252a5bbfe7\" class=\"colab-df-
container\">\n"," <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>SaleID</th>\n"," <th>Country</th>\
n"," <th>OrderMethod</th>\n"," <th>Retailer</th>\n"," <th>Line</th>\
n"," <th>Type</th>\n"," <th>Product</th>\n"," <th>YearOfSales</th>\
n"," <th>Quarter</th>\n"," <th>Revenue</th>\n"," <th>Quantity</th>\
n"," <th>Margin</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\
n"," <th>0</th>\n"," <td>SaleID</td>\n"," <td>RetailerCountry</td>\
n"," <td>OrderMethod</td>\n"," <td>RetailerType</td>\n","
<td>ProductLine</td>\n"," <td>ProductType</td>\n"," <td>Product</td>\n","
<td>Year</td>\n"," <td>Quarter</td>\n"," <td>Revenue</td>\n","
<td>Quantity</td>\n"," <td>GrossMargin</td>\n"," </tr>\n"," </tbody>\
n","</table>\n","</div>\n"," <div class=\"colab-df-buttons\">\n","\n"," <div
class=\"colab-df-container\">\n"," <button class=\"colab-df-convert\"
onclick=\"convertToInteractive('df-86e06034-ae8c-4319-898c-53252a5bbfe7')\"\n","
title=\"Convert this dataframe to an interactive table.\"\n","
style=\"display:none;\">\n","\n"," <svg xmlns=\"http://www.w3.org/2000/svg\"
height=\"24px\" viewBox=\"0 -960 960 960\">\n"," <path d=\"M120-120v-
720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-
160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-
160H180v160Zm440 0h160v-160H620v160Z\"/>\n"," </svg>\n"," </button>\n","\n","
<style>\n"," .colab-df-container {\n"," display:flex;\n"," gap: 12px;\
n"," }\n","\n"," .colab-df-convert {\n"," background-color: #E8F0FE;\
n"," border: none;\n"," border-radius: 50%;\n"," cursor: pointer;\
n"," display: none;\n"," fill: #1967D2;\n"," height: 32px;\n","
padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-
convert:hover {\n"," background-color: #E2EBFA;\n"," box-shadow: 0px 1px
2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill:
#174EA6;\n"," }\n","\n"," .colab-df-buttons div {\n"," margin-bottom:
4px;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n"," background-
color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n","
[theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n","
box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px
1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\
n","\n"," <script>\n"," const buttonEl =\n","
document.querySelector('#df-86e06034-ae8c-4319-898c-53252a5bbfe7 button.colab-df-
convert');\n"," buttonEl.style.display =\n","
google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function
convertToInteractive(key) {\n"," const element =
document.querySelector('#df-86e06034-ae8c-4319-898c-53252a5bbfe7');\n","
const dataTable =\n"," await
google.colab.kernel.invokeFunction('convertToInteractive',\n","
[key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml
= 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\"
href=https://colab.research.google.com/notebooks/data_table.ipynb>data table
notebook</a>'\n"," + ' to learn more about interactive tables.';\n","
element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n","
await google.colab.output.renderOutput(dataTable, element);\n"," const
docLink = document.createElement('div');\n"," docLink.innerHTML =
docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n","
</script>\n"," </div>\n","\n","\n"," </div>\n","
</div>\n"],"application/vnd.google.colaboratory.intrinsic+json":
{"type":"dataframe","variable_name":"df","summary":"{\n \"name\": \"df\",\
n \"rows\": 1,\n \"fields\": [\n {\n \"column\": \"SaleID\",\
n \"properties\": {\n \"dtype\": \"string\",\
n \"num_unique_values\": 1,\n \"samples\": [\n \"SaleID\"\n
],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\
n },\n {\n \"column\": \"Country\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"RetailerCountry\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"OrderMethod\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"OrderMethod\"\n ],\
n \"semantic_type\": \"\",\n
\"description\": \"\"\n }\n },\n {\n \"column\": \"Retailer\",\
n \"properties\": {\n \"dtype\": \"string\",\
n \"num_unique_values\": 1,\n \"samples\": [\
n \"RetailerType\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Line\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"ProductLine\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Type\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"ProductType\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Product\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Product\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"YearOfSales\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Year\"\n ],\n \"semantic_type\":
\"\",\n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Quarter\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Quarter\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Revenue\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Revenue\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Quantity\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Quantity\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Margin\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"GrossMargin\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n
]\n}"}},"metadata":{},"execution_count":47}],"source":["df.head()"]},
{"cell_type":"markdown","metadata":{"id":"o8bvjzA0Zhcc"},"source":["Use an
attribute to obtain metadata about the types of data stored in the different
columns of the **sales_products_data** DataFrame."]},
{"cell_type":"code","execution_count":48,"metadata":{"id":"yCOsM4ExZhcd","colab":
{"base_uri":"https://localhost:8080/","height":460},"executionInfo":
{"status":"ok","timestamp":1733940198228,"user_tz":-300,"elapsed":495,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"0dc71e47-4e0d-4821-f0fc-
22d3c19558d9"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["SaleID object\n","Country object\n","OrderMethod object\
n","Retailer object\n","Line object\n","Type object\
n","Product object\n","YearOfSales object\n","Quarter object\
n","Revenue object\n","Quantity object\n","Margin object\
n","dtype: object"],"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>0</th>\n","
</tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>SaleID</th>\n","
<td>object</td>\n"," </tr>\n"," <tr>\n"," <th>Country</th>\n","
<td>object</td>\n"," </tr>\n"," <tr>\n"," <th>OrderMethod</th>\n","
<td>object</td>\n"," </tr>\n"," <tr>\n"," <th>Retailer</th>\n","
<td>object</td>\n"," </tr>\n"," <tr>\n"," <th>Line</th>\n","
<td>object</td>\n"," </tr>\n"," <tr>\n"," <th>Type</th>\n","
<td>object</td>\n"," </tr>\n"," <tr>\n"," <th>Product</th>\n","
<td>object</td>\n"," </tr>\n"," <tr>\n"," <th>YearOfSales</th>\n","
<td>object</td>\n"," </tr>\n"," <tr>\n"," <th>Quarter</th>\n","
<td>object</td>\n"," </tr>\n"," <tr>\n"," <th>Revenue</th>\n","
<td>object</td>\n"," </tr>\n"," <tr>\n"," <th>Quantity</th>\n","
<td>object</td>\n"," </tr>\n"," <tr>\n"," <th>Margin</th>\n","
<td>object</td>\n"," </tr>\n","
</tbody>\n","</table>\n","</div><br><label><b>dtype:</b>
object</label>"]},"metadata":{},"execution_count":48}],"source":["df.dtypes"]},
{"cell_type":"markdown","metadata":{"id":"cW-0xWzuZhcd"},"source":["Obtain a Numpy
array containing all values of the **sales_products_data**.\n","<br/><br/> *Note:
There are two ways to achieve this! Try both, but keep in mind that pandas
developers advise us to stick to using the method.*"]},
{"cell_type":"code","execution_count":50,"metadata":{"id":"nG-
5YKj4Zhcd","executionInfo":{"status":"ok","timestamp":1733940432593,"user_tz":-
300,"elapsed":505,"user":{"displayName":"Almas
Islam","userId":"05912423101588664233"}}},"outputs":[],"source":["np_array =
np.array(sales_products_data)"]},
{"cell_type":"code","execution_count":51,"metadata":{"id":"kfVK5BdDZhce","colab":
{"base_uri":"https://localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733940440562,"user_tz":-300,"elapsed":668,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"330d8860-17a2-4d50-952a-
9791e5e5fe0d"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["array([['SaleID_1', 'United States', 'Fax', ..., 59728.66, 491.0,\n","
0.35754797],\n"," ['SaleID_2', 'United States', 'Fax', ..., 36050.32, 254.0,\
n"," 0.4842745],\n"," ['SaleID_3', 'United States', 'Fax', ...,
90040.48, 149.0, nan],\n"," ...,\n"," ['SaleID_1274', 'Spain', 'Sales
visit', ..., 12306.48, 238.0,\n"," 0.56842037],\n"," ['SaleID_1275',
'Spain', 'Sales visit', ..., 56499.0, 1472.0,\n"," 0.49066667],\n","
['SaleID_1276', 'Spain', 'Sales visit', ..., 89427.0, 1178.0,\n","
0.38689474]], dtype=object)"]},"metadata":{},"execution_count":51}],"source":
["np_array"]},{"cell_type":"markdown","metadata":{"id":"uXimEsRCZhce"},"source":
["Verify that the obtained objects are NumPy arrays with the help of the \"Type\"
function."]},{"cell_type":"code","source":["type(np_array)"],"metadata":{"colab":
{"base_uri":"https://localhost:8080/"},"id":"0yAcu9X657ea","executionInfo":
{"status":"ok","timestamp":1733940474075,"user_tz":-300,"elapsed":522,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"2c621256-4277-4214-9ca3-
3a861c7a4809"},"execution_count":52,"outputs":
[{"output_type":"execute_result","data":{"text/plain":
["numpy.ndarray"]},"metadata":{},"execution_count":52}]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"Px-
EbzHTZhcf"},"outputs":[],"source":["#Import the pandas and numpy libraries by using
the relevant well-known conventions.\n","\n","import pandas as pd\n","import numpy
as np"]},{"cell_type":"markdown","metadata":{"id":"2cNx1XnpZhcg"},"source":["Obtain
the number of rows and columns in the **sales_products_data** DataFrame."]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"3IyGwtTQZhcg","colab":
{"base_uri":"https://localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733922612750,"user_tz":-300,"elapsed":510,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"d2f5eb7e-dced-4f98-dce1-
e5449c237d8e"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["(1276, 12)"]},"metadata":{},"execution_count":95}],"source":
["sales_products_data.shape #shape of sales_products_data"]},
{"cell_type":"markdown","metadata":{"id":"8ZGK5_8RZhcg"},"source":["Check if the
output obtained in the previous cell is a tuple."]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"FaghsTsAZhch","colab":
{"base_uri":"https://localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733922652069,"user_tz":-300,"elapsed":524,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"8249d505-1830-49fa-d9ad-
acf80570696e"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["tuple"]},"metadata":{},"execution_count":96}],"source":
["type(sales_products_data.shape) #type of shape"]},
{"cell_type":"markdown","metadata":{"id":"J02KWLffZhch"},"source":["## Data
Selection in pandas DataFrames"]},{"cell_type":"markdown","metadata":
{"id":"J20GPdOcZhch"},"source":["Although we are not advised to, retrieve the data
from the 'Product' column from the **sales_products_data** column *without* using
the indexing operator **[ ]**."]},{"cell_type":"code","source":
["sales_products_data.Product #fetching \"Product\" data"],"metadata":{"colab":
{"base_uri":"https://localhost:8080/","height":458},"id":"fvPyDL0l3HLA","executionI
nfo":{"status":"ok","timestamp":1733923076679,"user_tz":-300,"elapsed":524,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"ab607c10-67f0-46d6-f87a-
30bc4f7dd582"},"execution_count":null,"outputs":
[{"output_type":"execute_result","data":{"text/plain":["0 TrailChef Deluxe
Cook Set\n","1 TrailChef Double Flame\n","2 Star
Dome\n","3 Star Gazer 2\n","4
Compact Relief Kit\n"," ... \n","1271
Husky Rope 60\n","1272 Firefly Climbing Lamp\n","1273 Firefly
Charger\n","1274 Granite Axe\n","1275 Granite
Extreme\n","Name: Product, Length: 1276, dtype: object"],"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>Product</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n","
<th>0</th>\n"," <td>TrailChef Deluxe Cook Set</td>\n"," </tr>\n"," <tr>\
n"," <th>1</th>\n"," <td>TrailChef Double Flame</td>\n"," </tr>\n","
<tr>\n"," <th>2</th>\n"," <td>Star Dome</td>\n"," </tr>\n"," <tr>\
n"," <th>3</th>\n"," <td>Star Gazer 2</td>\n"," </tr>\n"," <tr>\
n"," <th>4</th>\n"," <td>Compact Relief Kit</td>\n"," </tr>\n","
<tr>\n"," <th>...</th>\n"," <td>...</td>\n"," </tr>\n"," <tr>\n","
<th>1271</th>\n"," <td>Husky Rope 60</td>\n"," </tr>\n"," <tr>\n","
<th>1272</th>\n"," <td>Firefly Climbing Lamp</td>\n"," </tr>\n"," <tr>\
n"," <th>1273</th>\n"," <td>Firefly Charger</td>\n"," </tr>\n","
<tr>\n"," <th>1274</th>\n"," <td>Granite Axe</td>\n"," </tr>\n","
<tr>\n"," <th>1275</th>\n"," <td>Granite Extreme</td>\n"," </tr>\n","
</tbody>\n","</table>\n","<p>1276 rows × 1
columns</p>\n","</div><br><label><b>dtype:</b> object</label>"]},"metadata":
{},"execution_count":98}]},{"cell_type":"markdown","metadata":{"id":"Whed-
6idZhci"},"source":["Retrieve the data from the 'Product' column from the
**sales_products_data** column by using the indexing operator **[ ]**."]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"i5HBDZ-sZhci","colab":
{"base_uri":"https://localhost:8080/","height":458},"executionInfo":
{"status":"ok","timestamp":1733922879113,"user_tz":-300,"elapsed":573,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"dda9a09a-7de6-49c3-e7d4-
6841d7fbccdc"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["0
TrailChef Deluxe Cook Set\n","1 TrailChef Double Flame\n","2
Star Dome\n","3 Star Gazer 2\n","4 Compact Relief
Kit\n"," ... \n","1271 Husky Rope 60\
n","1272 Firefly Climbing Lamp\n","1273 Firefly Charger\
n","1274 Granite Axe\n","1275 Granite Extreme\
n","Name: Product, Length: 1276, dtype: object"],"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>Product</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n","
<th>0</th>\n"," <td>TrailChef Deluxe Cook Set</td>\n"," </tr>\n"," <tr>\
n"," <th>1</th>\n"," <td>TrailChef Double Flame</td>\n"," </tr>\n","
<tr>\n"," <th>2</th>\n"," <td>Star Dome</td>\n"," </tr>\n"," <tr>\
n"," <th>3</th>\n"," <td>Star Gazer 2</td>\n"," </tr>\n"," <tr>\
n"," <th>4</th>\n"," <td>Compact Relief Kit</td>\n"," </tr>\n","
<tr>\n"," <th>...</th>\n"," <td>...</td>\n"," </tr>\n"," <tr>\n","
<th>1271</th>\n"," <td>Husky Rope 60</td>\n"," </tr>\n"," <tr>\n","
<th>1272</th>\n"," <td>Firefly Climbing Lamp</td>\n"," </tr>\n"," <tr>\
n"," <th>1273</th>\n"," <td>Firefly Charger</td>\n"," </tr>\n","
<tr>\n"," <th>1274</th>\n"," <td>Granite Axe</td>\n"," </tr>\n","
<tr>\n"," <th>1275</th>\n"," <td>Granite Extreme</td>\n"," </tr>\n","
</tbody>\n","</table>\n","<p>1276 rows × 1
columns</p>\n","</div><br><label><b>dtype:</b> object</label>"]},"metadata":
{},"execution_count":97}],"source":["sales_products_data[\"Product\"]"]},
{"cell_type":"markdown","metadata":{"id":"zkJJRr8qZhcr"},"source":["Apply the
**.tail()** method to the code you used in your previous response to obtain the
last five rows from the \"Product\" column."]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"CJtJy12ZZhcs","colab":
{"base_uri":"https://localhost:8080/","height":241},"executionInfo":
{"status":"ok","timestamp":1733923120358,"user_tz":-300,"elapsed":543,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"2f716a97-08d7-465e-882e-
820d0f8a9311"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["1271 Husky Rope 60\n","1272 Firefly Climbing Lamp\n","1273
Firefly Charger\n","1274 Granite Axe\n","1275 Granite
Extreme\n","Name: Product, dtype: object"],"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>Product</th>\
n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>1271</th>\
n"," <td>Husky Rope 60</td>\n"," </tr>\n"," <tr>\n","
<th>1272</th>\n"," <td>Firefly Climbing Lamp</td>\n"," </tr>\n"," <tr>\
n"," <th>1273</th>\n"," <td>Firefly Charger</td>\n"," </tr>\n","
<tr>\n"," <th>1274</th>\n"," <td>Granite Axe</td>\n"," </tr>\n","
<tr>\n"," <th>1275</th>\n"," <td>Granite Extreme</td>\n"," </tr>\n","
</tbody>\n","</table>\n","</div><br><label><b>dtype:</b>
object</label>"]},"metadata":{},"execution_count":99}],"source":
["sales_products_data.Product.tail()"]},{"cell_type":"markdown","metadata":
{"id":"xN9DlZpLZhcs"},"source":["Although we are not advised to, retrieve the data
from the 'Quarter' column from the **sales_products_data** column *without* using
the indexing operator **.[ ]**."]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"Fhi0wdX_Zhcs","colab":
{"base_uri":"https://localhost:8080/","height":458},"executionInfo":
{"status":"ok","timestamp":1733923150289,"user_tz":-300,"elapsed":717,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"ae60af50-1702-4fc3-e51f-
58f260ad2b30"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["0
Q1 2018\n","1 Q1 2018\n","2 Q1 2018\n","3 Q1 2018\n","4 Q1
2018\n"," ... \n","1271 Q3 2020\n","1272 Q3 2020\n","1273 Q3
2020\n","1274 Q3 2020\n","1275 Q3 2020\n","Name: Quarter, Length: 1276,
dtype: object"],"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>Quarter</th>\
n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n","
<td>Q1 2018</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>Q1
2018</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>Q1
2018</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>Q1
2018</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n"," <td>Q1
2018</td>\n"," </tr>\n"," <tr>\n"," <th>...</th>\n"," <td>...</td>\
n"," </tr>\n"," <tr>\n"," <th>1271</th>\n"," <td>Q3 2020</td>\n","
</tr>\n"," <tr>\n"," <th>1272</th>\n"," <td>Q3 2020</td>\n","
</tr>\n"," <tr>\n"," <th>1273</th>\n"," <td>Q3 2020</td>\n","
</tr>\n"," <tr>\n"," <th>1274</th>\n"," <td>Q3 2020</td>\n","
</tr>\n"," <tr>\n"," <th>1275</th>\n"," <td>Q3 2020</td>\n","
</tr>\n"," </tbody>\n","</table>\n","<p>1276 rows × 1
columns</p>\n","</div><br><label><b>dtype:</b> object</label>"]},"metadata":
{},"execution_count":100}],"source":["sales_products_data.Quarter"]},
{"cell_type":"markdown","metadata":{"id":"5eRXxGGzZhct"},"source":["Retrieve the
data from the 'Quarter' column from the **sales_products_data** column by using the
indexing operator **[ ]**."]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"F2SQMGkzZhct","colab":
{"base_uri":"https://localhost:8080/","height":458},"executionInfo":
{"status":"ok","timestamp":1733923188589,"user_tz":-300,"elapsed":588,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"3fd727e2-eba4-4ef3-ed9a-
82088f68b99b"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["0
Q1 2018\n","1 Q1 2018\n","2 Q1 2018\n","3 Q1 2018\n","4 Q1
2018\n"," ... \n","1271 Q3 2020\n","1272 Q3 2020\n","1273 Q3
2020\n","1274 Q3 2020\n","1275 Q3 2020\n","Name: Quarter, Length: 1276,
dtype: object"],"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>Quarter</th>\n","
</tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n","
<td>Q1 2018</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>Q1
2018</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>Q1
2018</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>Q1
2018</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n"," <td>Q1
2018</td>\n"," </tr>\n"," <tr>\n"," <th>...</th>\n"," <td>...</td>\
n"," </tr>\n"," <tr>\n"," <th>1271</th>\n"," <td>Q3 2020</td>\n","
</tr>\n"," <tr>\n"," <th>1272</th>\n"," <td>Q3 2020</td>\n","
</tr>\n"," <tr>\n"," <th>1273</th>\n"," <td>Q3 2020</td>\n","
</tr>\n"," <tr>\n"," <th>1274</th>\n"," <td>Q3 2020</td>\n","
</tr>\n"," <tr>\n"," <th>1275</th>\n"," <td>Q3 2020</td>\n","
</tr>\n"," </tbody>\n","</table>\n","<p>1276 rows × 1
columns</p>\n","</div><br><label><b>dtype:</b> object</label>"]},"metadata":
{},"execution_count":101}],"source":["sales_products_data[\"Quarter\"]"]},
{"cell_type":"markdown","metadata":{"id":"A3cyKhBqZhct"},"source":["Use any of the
4 previous examples to verify that the data obtained from a column of a DataFrame
is actually stored in a Series object:"]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"kCQmIc40Zhcu","colab":
{"base_uri":"https://localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733923266467,"user_tz":-300,"elapsed":483,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"c3b4d822-eb12-4810-9851-
c83616927197"},"outputs":[{"output_type":"stream","name":"stdout","text":["<class
'pandas.core.series.Series'>\n"]}],"source":
["print(type(sales_products_data[\"Quarter\"]))"]},
{"cell_type":"markdown","metadata":{"id":"xSRGCibzZhcu"},"source":["<br> Use a
well-know attribute and attribute chaining to obtain information about the type of
data stored in the \"Revenue\" column."]},
{"cell_type":"code","execution_count":null,"metadata":
{"scrolled":true,"id":"R71GcwQnZhcu","colab":{"base_uri":"https://
localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733923384557,"user_tz":-300,"elapsed":514,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"7c7367e6-5419-4fa1-b529-
5fab6a4a1eba"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["dtype('float64')"]},"metadata":{},"execution_count":106}],"source":
["sales_products_data.Revenue.dtype"]},{"cell_type":"code","source":
["sales_products_data.info()"],"metadata":{"colab":{"base_uri":"https://
localhost:8080/"},"id":"YRql5VVr47TN","executionInfo":
{"status":"ok","timestamp":1733923452225,"user_tz":-300,"elapsed":606,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"cddec2d1-2c2f-4739-b6df-
4b60ebcb2661"},"execution_count":null,"outputs":
[{"output_type":"stream","name":"stdout","text":["<class
'pandas.core.frame.DataFrame'>\n","RangeIndex: 1276 entries, 0 to 1275\n","Data
columns (total 12 columns):\n"," # Column Non-Null Count Dtype \
n","--- ------ -------------- ----- \n"," 0 SaleID 1276
non-null object \n"," 1 RetailerCountry 1276 non-null object \n"," 2
OrderMethod 1271 non-null object \n"," 3 RetailerType 1273 non-null
object \n"," 4 ProductLine 1273 non-null object \n"," 5 ProductType
1273 non-null object \n"," 6 Product 1272 non-null object \n"," 7
Year 1275 non-null float64\n"," 8 Quarter 1276 non-null
object \n"," 9 Revenue 1260 non-null float64\n"," 10 Quantity
1273 non-null float64\n"," 11 GrossMargin 1250 non-null float64\
n","dtypes: float64(4), object(8)\n","memory usage: 119.8+ KB\n"]}]},
{"cell_type":"markdown","metadata":{"id":"XjXMVsEtZhcv"},"source":["**Selecting
multiple columns from a DF**"]},{"cell_type":"markdown","metadata":
{"id":"BYTUWrXGZhcv"},"source":["Use a list with column names within the indexing
operator ([ ]) to extract data from the 'Revenue' and 'Quantity' columns from the
**sales_products_data** DataFrame. Use the **.head()** method to only display the
top five rows of the selection. <br>\n","Solve the problem by using a single line
of code."]},{"cell_type":"code","execution_count":null,"metadata":
{"id":"E_i4WkJ7Zhcw","colab":{"base_uri":"https://
localhost:8080/","height":206},"executionInfo":
{"status":"ok","timestamp":1733923620577,"user_tz":-300,"elapsed":1217,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"61a4a990-cd54-4000-e851-
a01c43d0dd08"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["
Revenue Quantity\n","0 59728.66 491.0\n","1 36050.32 254.0\n","2
90040.48 149.0\n","3 NaN 305.0\n","4 NaN
182.0"],"text/html":["\n"," <div id=\"df-df667e07-c6f6-4bd0-8ea0-25ab44f11673\"
class=\"colab-df-container\">\n"," <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>Revenue</th>\
n"," <th>Quantity</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n","
<tr>\n"," <th>0</th>\n"," <td>59728.66</td>\n"," <td>491.0</td>\n","
</tr>\n"," <tr>\n"," <th>1</th>\n"," <td>36050.32</td>\n","
<td>254.0</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n","
<td>90040.48</td>\n"," <td>149.0</td>\n"," </tr>\n"," <tr>\n","
<th>3</th>\n"," <td>NaN</td>\n"," <td>305.0</td>\n"," </tr>\n","
<tr>\n"," <th>4</th>\n"," <td>NaN</td>\n"," <td>182.0</td>\n","
</tr>\n"," </tbody>\n","</table>\n","</div>\n"," <div class=\"colab-df-
buttons\">\n","\n"," <div class=\"colab-df-container\">\n"," <button
class=\"colab-df-convert\" onclick=\"convertToInteractive('df-df667e07-c6f6-4bd0-
8ea0-25ab44f11673')\"\n"," title=\"Convert this dataframe to an
interactive table.\"\n"," style=\"display:none;\">\n","\n"," <svg
xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\
n"," <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-
160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-
160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n"," </svg>\
n"," </button>\n","\n"," <style>\n"," .colab-df-container {\n","
display:flex;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n","
background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\
n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n","
height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\
n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n","
box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67,
0.15);\n"," fill: #174EA6;\n"," }\n","\n"," .colab-df-buttons div {\n","
margin-bottom: 4px;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n","
background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n","
[theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n","
box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px
1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\
n","\n"," <script>\n"," const buttonEl =\n","
document.querySelector('#df-df667e07-c6f6-4bd0-8ea0-25ab44f11673 button.colab-df-
convert');\n"," buttonEl.style.display =\n","
google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function
convertToInteractive(key) {\n"," const element =
document.querySelector('#df-df667e07-c6f6-4bd0-8ea0-25ab44f11673');\n","
const dataTable =\n"," await
google.colab.kernel.invokeFunction('convertToInteractive',\n","
[key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml
= 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\"
href=https://colab.research.google.com/notebooks/data_table.ipynb>data table
notebook</a>'\n"," + ' to learn more about interactive tables.';\n","
element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n","
await google.colab.output.renderOutput(dataTable, element);\n"," const
docLink = document.createElement('div');\n"," docLink.innerHTML =
docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n","
</script>\n"," </div>\n","\n","\n","<div id=\"df-80d68808-bab5-4cda-87c4-
caa0dfb01a0a\">\n"," <button class=\"colab-df-quickchart\"
onclick=\"quickchart('df-80d68808-bab5-4cda-87c4-caa0dfb01a0a')\"\n","
title=\"Suggest charts\"\n"," style=\"display:none;\">\n","\n","<svg
xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n","
width=\"24px\">\n"," <g>\n"," <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0
1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-
2v-4h2v4z\"/>\n"," </g>\n","</svg>\n"," </button>\n","\n","<style>\
n"," .colab-df-quickchart {\n","
--bg-color: #E8F0FE;\n"," --fill-color: #1967D2;\n"," --hover-bg-
color: #E2EBFA;\n"," --hover-fill-color: #174EA6;\n"," --disabled-fill-
color: #AAA;\n"," --disabled-bg-color: #DDD;\n"," }\n","\n","
[theme=dark] .colab-df-quickchart {\n"," --bg-color: #3B4455;\n"," --
fill-color: #D2E3FC;\n"," --hover-bg-color: #434B5C;\n"," --hover-fill-
color: #FFFFFF;\n"," --disabled-bg-color: #3B4455;\n"," --disabled-fill-
color: #666;\n"," }\n","\n"," .colab-df-quickchart {\n"," background-color:
var(--bg-color);\n"," border: none;\n"," border-radius: 50%;\n"," cursor:
pointer;\n"," display: none;\n"," fill: var(--fill-color);\n"," height:
32px;\n"," padding: 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-
quickchart:hover {\n"," background-color: var(--hover-bg-color);\n"," box-
shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n","
fill: var(--button-hover-fill-color);\n"," }\n","\n"," .colab-df-quickchart-
complete:disabled,\n"," .colab-df-quickchart-complete:disabled:hover {\n","
background-color: var(--disabled-bg-color);\n"," fill: var(--disabled-fill-
color);\n"," box-shadow: none;\n"," }\n","\n"," .colab-df-spinner {\n","
border: 2px solid var(--fill-color);\n"," border-color: transparent;\n","
border-bottom-color: var(--fill-color);\n"," animation:\n"," spin 1s
steps(1) infinite;\n"," }\n","\n"," @keyframes spin {\n"," 0% {\n","
border-color: transparent;\n"," border-bottom-color: var(--fill-color);\n","
border-left-color: var(--fill-color);\n"," }\n"," 20% {\n"," border-
color: transparent;\n"," border-left-color: var(--fill-color);\n","
border-top-color: var(--fill-color);\n"," }\n"," 30% {\n"," border-
color: transparent;\n"," border-left-color: var(--fill-color);\n","
border-top-color: var(--fill-color);\n"," border-right-color: var(--fill-
color);\n"," }\n"," 40% {\n"," border-color: transparent;\n","
border-right-color: var(--fill-color);\n"," border-top-color: var(--fill-
color);\n"," }\n"," 60% {\n"," border-color: transparent;\n","
border-right-color: var(--fill-color);\n"," }\n"," 80% {\n"," border-
color: transparent;\n"," border-right-color: var(--fill-color);\n","
border-bottom-color: var(--fill-color);\n"," }\n"," 90% {\n"," border-
color: transparent;\n"," border-bottom-color: var(--fill-color);\n"," }\
n"," }\n","</style>\n","\n"," <script>\n"," async function quickchart(key) {\
n"," const quickchartButtonEl =\n"," document.querySelector('#' + key +
' button');\n"," quickchartButtonEl.disabled = true; // To prevent multiple
clicks.\n"," quickchartButtonEl.classList.add('colab-df-spinner');\n","
try {\n"," const charts = await google.colab.kernel.invokeFunction(\n","
'suggestCharts', [key], {});\n"," } catch (error) {\n","
console.error('Error during call to suggestCharts:', error);\n"," }\n","
quickchartButtonEl.classList.remove('colab-df-spinner');\n","
quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n"," }\n","
(() => {\n"," let quickchartButtonEl =\n","
document.querySelector('#df-80d68808-bab5-4cda-87c4-caa0dfb01a0a button');\n","
quickchartButtonEl.style.display =\n"," google.colab.kernel.accessAllowed ?
'block' : 'none';\n"," })();\n"," </script>\n","</div>\n","\n"," </div>\n","
</div>\n"],"application/vnd.google.colaboratory.intrinsic+json":
{"type":"dataframe","summary":"{\
n \"name\": \"sales_products_data[[\\\"Revenue\\\",\\\"Quantity\\\"]]\",\
n \"rows\": 5,\n \"fields\": [\n {\n \"column\": \"Revenue\",\
n \"properties\": {\n \"dtype\": \"number\",\n \"std\":
27062.91310290893,\n \"min\": 36050.32,\n \"max\": 90040.48,\n
\"num_unique_values\": 3,\n \"samples\": [\n 59728.66,\n
36050.32,\n 90040.48\n ],\n \"semantic_type\": \"\",\n
\"description\": \"\"\n }\n },\n {\n \"column\": \"Quantity\",\n
\"properties\": {\n \"dtype\": \"number\",\n \"std\":
134.64286093217123,\n \"min\": 149.0,\n \"max\": 491.0,\
n \"num_unique_values\": 5,\n \"samples\": [\n 254.0,\n
182.0,\n 149.0\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":
{},"execution_count":110}],"source":
["sales_products_data[[\"Revenue\",\"Quantity\"]].head()"]},
{"cell_type":"markdown","metadata":{"id":"XfxTk2JUZhcw"},"source":["Can you think
of a more elegant way to obtain the same result? This option is more often
encountered in professional work since it improves the legibility of your code."]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"0O9O78DaZhcx","colab":
{"base_uri":"https://localhost:8080/","height":206},"executionInfo":
{"status":"ok","timestamp":1733929059819,"user_tz":-300,"elapsed":511,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"15e31525-6586-49dd-8082-
ef05e1568401"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["
Revenue Quantity\n","0 59728.66 491.0\n","1 36050.32 254.0\n","2
90040.48 149.0\n","3 NaN 305.0\n","4 NaN
182.0"],"text/html":["\n"," <div id=\"df-3097ec54-9d39-4dff-8617-548181ea97c0\"
class=\"colab-df-container\">\n"," <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>Revenue</th>\
n"," <th>Quantity</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n","
<tr>\n"," <th>0</th>\n"," <td>59728.66</td>\n"," <td>491.0</td>\n","
</tr>\n"," <tr>\n"," <th>1</th>\n"," <td>36050.32</td>\n","
<td>254.0</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n","
<td>90040.48</td>\n"," <td>149.0</td>\n"," </tr>\n"," <tr>\n","
<th>3</th>\n"," <td>NaN</td>\n"," <td>305.0</td>\n"," </tr>\n","
<tr>\n"," <th>4</th>\n"," <td>NaN</td>\n"," <td>182.0</td>\n","
</tr>\n"," </tbody>\n","</table>\n","</div>\n"," <div class=\"colab-df-
buttons\">\n","\n"," <div class=\"colab-df-container\">\n"," <button
class=\"colab-df-convert\" onclick=\"convertToInteractive('df-3097ec54-9d39-4dff-
8617-548181ea97c0')\"\n"," title=\"Convert this dataframe to an
interactive table.\"\n"," style=\"display:none;\">\n","\n"," <svg
xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\
n"," <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-
160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-
160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n"," </svg>\
n"," </button>\n","\n"," <style>\n"," .colab-df-container {\n","
display:flex;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n","
background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\
n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n","
height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\
n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n","
box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67,
0.15);\n"," fill: #174EA6;\n"," }\n","\n"," .colab-df-buttons div {\n","
margin-bottom: 4px;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n","
background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n","
[theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n","
box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px
1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\
n","\n"," <script>\n"," const buttonEl =\n","
document.querySelector('#df-3097ec54-9d39-4dff-8617-548181ea97c0 button.colab-df-
convert');\n"," buttonEl.style.display =\n","
google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function
convertToInteractive(key) {\n"," const element =
document.querySelector('#df-3097ec54-9d39-4dff-8617-548181ea97c0');\n","
const dataTable =\n"," await
google.colab.kernel.invokeFunction('convertToInteractive',\n","
[key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml
= 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\"
href=https://colab.research.google.com/notebooks/data_table.ipynb>data table
notebook</a>'\n"," + ' to learn more about interactive tables.';\n","
element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n","
await google.colab.output.renderOutput(dataTable, element);\n"," const
docLink = document.createElement('div');\n"," docLink.innerHTML =
docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n","
</script>\n"," </div>\n","\n","\n","<div id=\"df-8a682cb7-d853-47cd-b15d-
f2ab1230b5ae\">\n"," <button class=\"colab-df-quickchart\"
onclick=\"quickchart('df-8a682cb7-d853-47cd-b15d-f2ab1230b5ae')\"\n","
title=\"Suggest charts\"\n"," style=\"display:none;\">\n","\n","<svg
xmlns=\"http://www.w3.org/2000/svg\"
height=\"24px\"viewBox=\"0 0 24 24\"\n"," width=\"24px\">\n"," <g>\n","
<path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-
2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n"," </g>\n","</svg>\n","
</button>\n","\n","<style>\n"," .colab-df-quickchart {\n"," --bg-color:
#E8F0FE;\n"," --fill-color: #1967D2;\n"," --hover-bg-color: #E2EBFA;\n","
--hover-fill-color: #174EA6;\n"," --disabled-fill-color: #AAA;\n"," --
disabled-bg-color: #DDD;\n"," }\n","\n"," [theme=dark] .colab-df-quickchart {\
n"," --bg-color: #3B4455;\n"," --fill-color: #D2E3FC;\n"," --hover-
bg-color: #434B5C;\n"," --hover-fill-color: #FFFFFF;\n"," --disabled-bg-
color: #3B4455;\n"," --disabled-fill-color: #666;\n"," }\n","\n"," .colab-
df-quickchart {\n"," background-color: var(--bg-color);\n"," border: none;\
n"," border-radius: 50%;\n"," cursor: pointer;\n"," display: none;\n","
fill: var(--fill-color);\n"," height: 32px;\n"," padding: 0;\n"," width:
32px;\n"," }\n","\n"," .colab-df-quickchart:hover {\n"," background-color:
var(--hover-bg-color);\n"," box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px
3px 1px rgba(60, 64, 67, 0.15);\n"," fill: var(--button-hover-fill-color);\n","
}\n","\n"," .colab-df-quickchart-complete:disabled,\n"," .colab-df-quickchart-
complete:disabled:hover {\n"," background-color: var(--disabled-bg-color);\n","
fill: var(--disabled-fill-color);\n"," box-shadow: none;\n"," }\n","\
n"," .colab-df-spinner {\n"," border: 2px solid var(--fill-color);\n","
border-color: transparent;\n"," border-bottom-color: var(--fill-color);\n","
animation:\n"," spin 1s steps(1) infinite;\n"," }\n","\n"," @keyframes spin
{\n"," 0% {\n"," border-color: transparent;\n"," border-bottom-color:
var(--fill-color);\n"," border-left-color: var(--fill-color);\n"," }\n","
20% {\n"," border-color: transparent;\n"," border-left-color: var(--fill-
color);\n"," border-top-color: var(--fill-color);\n"," }\n"," 30% {\n","
border-color: transparent;\n"," border-left-color: var(--fill-color);\n","
border-top-color: var(--fill-color);\n"," border-right-color: var(--fill-
color);\n"," }\n"," 40% {\n"," border-color: transparent;\n","
border-right-color: var(--fill-color);\n"," border-top-color: var(--fill-
color);\n"," }\n"," 60% {\n"," border-color: transparent;\n","
border-right-color: var(--fill-color);\n"," }\n"," 80% {\n"," border-
color: transparent;\n"," border-right-color: var(--fill-color);\n","
border-bottom-color: var(--fill-color);\n"," }\n"," 90% {\n"," border-
color: transparent;\n"," border-bottom-color: var(--fill-color);\n"," }\
n"," }\n","</style>\n","\n"," <script>\n"," async function quickchart(key) {\
n"," const quickchartButtonEl =\n"," document.querySelector('#' + key +
' button');\n"," quickchartButtonEl.disabled = true; // To prevent multiple
clicks.\n"," quickchartButtonEl.classList.add('colab-df-spinner');\n","
try {\n"," const charts = await google.colab.kernel.invokeFunction(\n","
'suggestCharts', [key], {});\n"," } catch (error) {\n","
console.error('Error during call to suggestCharts:', error);\n"," }\n","
quickchartButtonEl.classList.remove('colab-df-spinner');\n","
quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n"," }\n","
(() => {\n"," let quickchartButtonEl =\n","
document.querySelector('#df-8a682cb7-d853-47cd-b15d-f2ab1230b5ae button');\n","
quickchartButtonEl.style.display =\n"," google.colab.kernel.accessAllowed ?
'block' : 'none';\n"," })();\n"," </script>\n","</div>\n","\n"," </div>\n","
</div>\n"],"application/vnd.google.colaboratory.intrinsic+json":
{"type":"dataframe","summary":"{\n \"name\": \"sales_products_data\",\n \"rows\":
5,\n \"fields\": [\n {\n \"column\": \"Revenue\",\n \"properties\":
{\n \"dtype\": \"number\",\n \"std\": 27062.91310290893,\
n \"min\": 36050.32,\n \"max\": 90040.48,\
n \"num_unique_values\": 3,\n \"samples\": [\n 59728.66,\n
36050.32,\n 90040.48\n ],\n \"semantic_type\": \"\",\n
\"description\": \"\"\n }\n },\n {\n \"column\": \"Quantity\",\n
\"properties\": {\n \"dtype\": \"number\",\n \"std\":
134.64286093217123,\n \"min\": 149.0,\n \"max\": 491.0,\
n \"num_unique_values\": 5,\n \"samples\": [\n 254.0,\n
182.0,\n 149.0\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":
{},"execution_count":159}],"source":["sales_products_data.loc[:,
[\"Revenue\",\"Quantity\"]].head()"]},{"cell_type":"markdown","source":["This could
be a method but first one seems more better."],"metadata":{"id":"m8jALDUiOi9W"}},
{"cell_type":"markdown","metadata":{"id":"xJ1X0s3FZhcx"},"source":["## pandas
DataFrames - Indexing with .iloc[]"]},{"cell_type":"markdown","metadata":
{"id":"QRd5Ag2AZhcy"},"source":["Select the data from the first row from the
**sales_products_data** DataFrame (don't forget that in programming we start
counting from 0!)."]},{"cell_type":"code","execution_count":null,"metadata":
{"id":"M_1OGnOeZhcy","colab":{"base_uri":"https://
localhost:8080/","height":135},"executionInfo":
{"status":"ok","timestamp":1733924676650,"user_tz":-300,"elapsed":525,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"72226d02-e061-49be-babd-
491a463e82cf"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["
SaleID RetailerCountry OrderMethod RetailerType ProductLine \\\n","0
SaleID_1 United States Fax Outdoors Shop Personal Accessories \n","\
n"," ProductType Product Year Quarter Revenue \\\n","0
Cooking Gear TrailChef Deluxe Cook Set 2018.0 Q1 2018 59728.66 \n","\n","
Quantity GrossMargin \n","0 491.0 0.357548 "],"text/html":["\n"," <div
id=\"df-699a9177-4f60-4883-8938-aa000a7843b3\" class=\"colab-df-container\">\n","
<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>SaleID</th>\n"," <th>RetailerCountry</th>\n"," <th>OrderMethod</th>\
n"," <th>RetailerType</th>\n"," <th>ProductLine</th>\n","
<th>ProductType</th>\n"," <th>Product</th>\n"," <th>Year</th>\n","
<th>Quarter</th>\n"," <th>Revenue</th>\n"," <th>Quantity</th>\n","
<th>GrossMargin</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n","
<th>0</th>\n"," <td>SaleID_1</td>\n"," <td>United States</td>\n","
<td>Fax</td>\n"," <td>Outdoors Shop</td>\n"," <td>Personal
Accessories</td>\n"," <td>Cooking Gear</td>\n"," <td>TrailChef Deluxe
Cook Set</td>\n"," <td>2018.0</td>\n"," <td>Q1 2018</td>\n","
<td>59728.66</td>\n"," <td>491.0</td>\n"," <td>0.357548</td>\n","
</tr>\n"," </tbody>\n","</table>\n","</div>\n"," <div class=\"colab-df-
buttons\">\n","\n"," <div class=\"colab-df-container\">\n"," <button
class=\"colab-df-convert\" onclick=\"convertToInteractive('df-699a9177-4f60-4883-
8938-aa000a7843b3')\"\n"," title=\"Convert this dataframe to an
interactive table.\"\n"," style=\"display:none;\">\n","\n"," <svg
xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\
n"," <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-
160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-
160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n"," </svg>\
n"," </button>\n","\n"," <style>\n"," .colab-df-container {\n","
display:flex;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n","
background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\
n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n","
height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\
n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n","
box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67,
0.15);\n"," fill: #174EA6;\n"," }\n","\n"," .colab-df-buttons div {\n","
margin-bottom: 4px;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n","
background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n","
[theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n","
box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px
1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\
n","\n"," <script>\n"," const buttonEl =\n","
document.querySelector('#df-699a9177-4f60-4883-8938-aa000a7843b3 button.colab-df-
convert');\n"," buttonEl.style.display =\n","
google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function
convertToInteractive(key) {\n"," const element =
document.querySelector('#df-699a9177-4f60-4883-8938-aa000a7843b3');\n","
const dataTable =\n"," await
google.colab.kernel.invokeFunction('convertToInteractive',\n","
[key], {});\n"," if (!dataTable) return;\n","\n"," const
docLinkHtml = 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\"
href=https://colab.research.google.com/notebooks/data_table.ipynb>data table
notebook</a>'\n"," + ' to learn more about interactive tables.';\n","
element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n","
await google.colab.output.renderOutput(dataTable, element);\n"," const
docLink = document.createElement('div');\n"," docLink.innerHTML =
docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n","
</script>\n"," </div>\n","\n","\n"," </div>\n","
</div>\n"],"application/vnd.google.colaboratory.intrinsic+json":
{"type":"dataframe","summary":"{\n \"name\": \"sales_products_data\",\n \"rows\":
1,\n \"fields\": [\n {\n \"column\": \"SaleID\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"SaleID_1\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"RetailerCountry\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"United States\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"OrderMethod\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Fax\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"RetailerType\",\n \"properties\": {\n \"dtype\":
\"string\",\n \"num_unique_values\": 1,\n \"samples\": [\
n \"Outdoors Shop\"\n ],\n \"semantic_type\": \"\",\n
\"description\": \"\"\n }\n },\n {\n \"column\": \"ProductLine\",\n
\"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\":
1,\n \"samples\": [\n \"Personal Accessories\"\n ],\n
\"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n
\"column\": \"ProductType\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Cooking Gear\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Product\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"TrailChef Deluxe Cook Set\"\n ],\n
\"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n
\"column\": \"Year\",\n \"properties\": {\n \"dtype\": \"number\",\n
\"std\": null,\n \"min\": 2018.0,\n \"max\": 2018.0,\
n \"num_unique_values\": 1,\n \"samples\": [\n 2018.0\n
],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\
n },\n {\n \"column\": \"Quarter\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Q1 2018\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Revenue\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": null,\n \"min\":
59728.66,\n \"max\": 59728.66,\n \"num_unique_values\": 1,\
n \"samples\": [\n 59728.66\n ],\n \"semantic_type\":
\"\",\n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Quantity\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": null,\n \"min\": 491.0,\n
\"max\": 491.0,\n \"num_unique_values\": 1,\n \"samples\": [\n
491.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\
n }\n },\n {\n \"column\": \"GrossMargin\",\n \"properties\":
{\n \"dtype\": \"number\",\n \"std\": null,\n \"min\":
0.35754797,\n \"max\": 0.35754797,\n \"num_unique_values\": 1,\n
\"samples\": [\n 0.35754797\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":
{},"execution_count":133}],"source":["sales_products_data.iloc[0:1]"]},
{"cell_type":"markdown","metadata":{"id":"Shj1HGgJZhcz"},"source":["Select the data
from the penultimate row from the **sales_products_data** DataFrame."]},
{"cell_type":"code","execution_count":null,"metadata":{"scrolled":true,"id":"-
Mpzo7C9Zhcz","colab":{"base_uri":"https://
localhost:8080/","height":118},"executionInfo":
{"status":"ok","timestamp":1733924483745,"user_tz":-300,"elapsed":640,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"a2eb3d21-c2f3-4c44-a46e-
09764d576ea8"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["
SaleID RetailerCountry OrderMethod RetailerType \\\n","1274 SaleID_1275
Spain Sales visit Outdoors Shop \n","\n"," ProductLine
ProductType Product Year Quarter Revenue \\\n","1274 Personal
Accessories Tools Granite Axe 2020.0 Q3 2020 56499.0 \n","\n","
Quantity GrossMargin \n","1274 1472.0 0.490667 "],"text/html":["\n","
<div id=\"df-fc6e34ee-1937-4cfe-b44a-072704efab29\" class=\"colab-df-container\">\
n"," <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>SaleID</th>\n"," <th>RetailerCountry</th>\n"," <th>OrderMethod</th>\
n"," <th>RetailerType</th>\n"," <th>ProductLine</th>\n","
<th>ProductType</th>\n"," <th>Product</th>\n"," <th>Year</th>\n","
<th>Quarter</th>\n"," <th>Revenue</th>\n"," <th>Quantity</th>\n","
<th>GrossMargin</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n","
<th>1274</th>\n"," <td>SaleID_1275</td>\n"," <td>Spain</td>\n","
<td>Sales visit</td>\n"," <td>Outdoors Shop</td>\n"," <td>Personal
Accessories</td>\n"," <td>Tools</td>\n"," <td>Granite Axe</td>\n","
<td>2020.0</td>\n"," <td>Q3 2020</td>\n"," <td>56499.0</td>\n","
<td>1472.0</td>\n"," <td>0.490667</td>\n"," </tr>\n","
</tbody>\n","</table>\n","</div>\n"," <div class=\"colab-df-buttons\">\n","\n","
<div class=\"colab-df-container\">\n"," <button class=\"colab-df-convert\"
onclick=\"convertToInteractive('df-fc6e34ee-1937-4cfe-b44a-072704efab29')\"\n","
title=\"Convert this dataframe to an interactive table.\"\n","
style=\"display:none;\">\n","\n"," <svg xmlns=\"http://www.w3.org/2000/svg\"
height=\"24px\" viewBox=\"0 -960 960 960\">\n"," <path d=\"M120-120v-
720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-
160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-
160H180v160Zm440 0h160v-160H620v160Z\"/>\n"," </svg>\n"," </button>\n","\n","
<style>\n"," .colab-df-container {\n"," display:flex;\n"," gap: 12px;\
n"," }\n","\n"," .colab-df-convert {\n"," background-color: #E8F0FE;\
n"," border: none;\n"," border-radius: 50%;\n"," cursor: pointer;\
n"," display: none;\n"," fill: #1967D2;\n"," height: 32px;\n","
padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-
convert:hover {\n"," background-color: #E2EBFA;\n"," box-shadow: 0px 1px
2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill:
#174EA6;\n"," }\n","\n"," .colab-df-buttons div {\n"," margin-bottom:
4px;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n"," background-
color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n","
[theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n","
box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px
1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\
n","\n"," <script>\n"," const buttonEl =\n","
document.querySelector('#df-fc6e34ee-1937-4cfe-b44a-072704efab29 button.colab-df-
convert');\n"," buttonEl.style.display =\n","
google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function
convertToInteractive(key) {\n"," const element =
document.querySelector('#df-fc6e34ee-1937-4cfe-b44a-072704efab29');\n","
const dataTable =\n"," await
google.colab.kernel.invokeFunction('convertToInteractive',\n","
[key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml
= 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\"
href=https://colab.research.google.com/notebooks/data_table.ipynb>data table
notebook</a>'\n"," + ' to learn more about interactive tables.';\n","
element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n","
await google.colab.output.renderOutput(dataTable, element);\n"," const
docLink = document.createElement('div');\n"," docLink.innerHTML =
docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n","
</script>\n"," </div>\n","\n","\n"," </div>\n","
</div>\n"],"application/vnd.google.colaboratory.intrinsic+json":
{"type":"dataframe","summary":"{\n
\"name\": \"sales_products_data\",\n \"rows\": 1,\n \"fields\": [\n {\n
\"column\": \"SaleID\",\n \"properties\": {\n \"dtype\": \"string\",\n
\"num_unique_values\": 1,\n \"samples\": [\n \"SaleID_1275\"\n
],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\
n },\n {\n \"column\": \"RetailerCountry\",\n \"properties\": {\n
\"dtype\": \"string\",\n \"num_unique_values\": 1,\n \"samples\": [\n
\"Spain\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"OrderMethod\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Sales visit\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"RetailerType\",\n \"properties\": {\n \"dtype\":
\"string\",\n \"num_unique_values\": 1,\n \"samples\": [\
n \"Outdoors Shop\"\n ],\n \"semantic_type\": \"\",\n
\"description\": \"\"\n }\n },\n {\n \"column\": \"ProductLine\",\n
\"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\":
1,\n \"samples\": [\n \"Personal Accessories\"\n ],\n
\"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n
\"column\": \"ProductType\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Tools\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Product\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Granite Axe\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Year\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": null,\n \"min\": 2020.0,\n
\"max\": 2020.0,\n \"num_unique_values\": 1,\n \"samples\": [\n
2020.0\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Quarter\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Q3 2020\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Revenue\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": null,\n \"min\": 56499.0,\
n \"max\": 56499.0,\n \"num_unique_values\": 1,\n \"samples\":
[\n 56499.0\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Quantity\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": null,\n \"min\": 1472.0,\n
\"max\": 1472.0,\n \"num_unique_values\": 1,\n \"samples\": [\n
1472.0\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"GrossMargin\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": null,\n \"min\":
0.49066667,\n \"max\": 0.49066667,\n \"num_unique_values\": 1,\n
\"samples\": [\n 0.49066667\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":
{},"execution_count":127}],"source":["sales_products_data.iloc[1274:1275]"]},
{"cell_type":"markdown","metadata":{"id":"MhPaeIIPZhc0"},"source":["Select the
value from the second row and sixth column of **sales_products_data** by using the
**.iloc[]** accessor.\n","<br><br> *Hint: If you've worked correctly, you should
obtain 'Cooking Gear'.*"]},{"cell_type":"code","source":
["sales_products_data.iloc[0,5]"],"metadata":{"colab":{"base_uri":"https://
localhost:8080/","height":35},"id":"U7TnO72d-vPL","executionInfo":
{"status":"ok","timestamp":1733924960811,"user_tz":-300,"elapsed":538,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"ac2e379f-fc78-43c6-cd60-
0cae9af5d5a6"},"execution_count":null,"outputs":
[{"output_type":"execute_result","data":{"text/plain":["'Cooking
Gear'"],"application/vnd.google.colaboratory.intrinsic+json":
{"type":"string"}},"metadata":{},"execution_count":139}]},
{"cell_type":"markdown","metadata":{"id":"xQIQjUbKZhc1"},"source":["Use the
**.shape** attribute to discover the largest numbers that you can use as arguments
of the **.iloc[]** accessor."]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"bMSG29VFZhc1","colab":
{"base_uri":"https://localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733924708890,"user_tz":-300,"elapsed":492,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"49d1844e-bcf3-4a2f-e2f4-
14cdc4641562"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["(1276, 12)"]},"metadata":{},"execution_count":134}],"source":
["sales_products_data.shape"]},{"cell_type":"markdown","source":["We can use
[1275,11] as the largest number to be used as an argument for iloc[]."],"metadata":
{"id":"PRBrEaKS97Sm"}},{"cell_type":"markdown","metadata":
{"id":"_JP7YhsjZhc1"},"source":["Considering the values you just obtained, use the
**.iloc[]** accessor find out the value that has been stored in the last row and
farthest-to-the-right column."]},{"cell_type":"markdown","source":["Last row is
1275 and farthest-to-the-right column is \"GrossMargin\" i.e., column 12(index
11)"],"metadata":{"id":"B14eItaR_ofe"}},
{"cell_type":"code","execution_count":null,"metadata":{"id":"2thCjReBZhc0","colab":
{"base_uri":"https://localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733925433511,"user_tz":-300,"elapsed":9,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"b0f1b714-1dd0-489e-c9d1-
b582e4af2d95"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["0.38689474"]},"metadata":{},"execution_count":142}],"source":
["sales_products_data.iloc[1275,11]"]},{"cell_type":"markdown","metadata":
{"id":"l3VoE6_5Zhc2"},"source":["Verify that you've obtained the correct value by
applying the **.tail()** method to the **sales_products_data** DataFrame.\n","<br>
Observe the value that is farthest to the right on the last row."]},
{"cell_type":"code","execution_count":null,"metadata":
{"scrolled":true,"id":"fTIn_o0aZhc2","colab":{"base_uri":"https://
localhost:8080/","height":330},"executionInfo":
{"status":"ok","timestamp":1733925342253,"user_tz":-300,"elapsed":1570,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"473b6fee-660c-4b7b-d6f0-
76ddf298c7c2"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["
SaleID RetailerCountry OrderMethod RetailerType \\\n","1271 SaleID_1272
Spain Sales visit Outdoors Shop \n","1272 SaleID_1273 Spain Sales
visit Outdoors Shop \n","1273 SaleID_1274 Spain Sales visit
Outdoors Shop \n","1274 SaleID_1275 Spain Sales visit Outdoors Shop
\n","1275 SaleID_1276 Spain Sales visit Outdoors Shop \n","\n","
ProductLine ProductType Product \\\n","1271 Personal
Accessories Rope Husky Rope 60 \n","1272 Outdoor
Protection Climbing Accessories Firefly Climbing Lamp \n","1273 Personal
Accessories Climbing Accessories Firefly Charger \n","1274 Personal
Accessories Tools Granite Axe \n","1275 Camping
Equipment Tools Granite Extreme \n","\n"," Year
Quarter Revenue Quantity GrossMargin \n","1271 2020.0 Q3 2020 30916.50
173.0 0.298114 \n","1272 2020.0 Q3 2020 7536.29 193.0 0.445287 \
n","1273 2020.0 Q3 2020 12306.48 238.0 0.568420 \n","1274 2020.0 Q3
2020 56499.00 1472.0 0.490667 \n","1275 2020.0 Q3 2020 89427.00
1178.0 0.386895 "],"text/html":["\n"," <div id=\"df-6ac69492-9c4f-498a-a6c1-
ef49b29afb09\" class=\"colab-df-container\">\n"," <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>SaleID</th>\
n"," <th>RetailerCountry</th>\n"," <th>OrderMethod</th>\n","
<th>RetailerType</th>\n"," <th>ProductLine</th>\n","
<th>ProductType</th>\n"," <th>Product</th>\n"," <th>Year</th>\n","
<th>Quarter</th>\n"," <th>Revenue</th>\n"," <th>Quantity</th>\n","
<th>GrossMargin</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n","
<th>1271</th>\n"," <td>SaleID_1272</td>\n"," <td>Spain</td>\n","
<td>Sales visit</td>\n"," <td>Outdoors Shop</td>\n"," <td>Personal
Accessories</td>\n"," <td>Rope</td>\n"," <td>Husky Rope 60</td>\n","
<td>2020.0</td>\n"," <td>Q3 2020</td>\n"," <td>30916.50</td>\n","
<td>173.0</td>\n"," <td>0.298114</td>\n"," </tr>\n"," <tr>\n","
<th>1272</th>\n"," <td>SaleID_1273</td>\n"," <td>Spain</td>\n","
<td>Sales visit</td>\n"," <td>Outdoors Shop</td>\n"," <td>Outdoor
Protection</td>\n"," <td>Climbing Accessories</td>\n"," <td>Firefly
Climbing Lamp</td>\n","
<td>2020.0</td>\n"," <td>Q3 2020</td>\n"," <td>7536.29</td>\n","
<td>193.0</td>\n"," <td>0.445287</td>\n"," </tr>\n"," <tr>\n","
<th>1273</th>\n"," <td>SaleID_1274</td>\n"," <td>Spain</td>\n","
<td>Sales visit</td>\n"," <td>Outdoors Shop</td>\n"," <td>Personal
Accessories</td>\n"," <td>Climbing Accessories</td>\n"," <td>Firefly
Charger</td>\n"," <td>2020.0</td>\n"," <td>Q3 2020</td>\n","
<td>12306.48</td>\n"," <td>238.0</td>\n"," <td>0.568420</td>\n","
</tr>\n"," <tr>\n"," <th>1274</th>\n"," <td>SaleID_1275</td>\n","
<td>Spain</td>\n"," <td>Sales visit</td>\n"," <td>Outdoors Shop</td>\n","
<td>Personal Accessories</td>\n"," <td>Tools</td>\n"," <td>Granite
Axe</td>\n"," <td>2020.0</td>\n"," <td>Q3 2020</td>\n","
<td>56499.00</td>\n"," <td>1472.0</td>\n"," <td>0.490667</td>\n","
</tr>\n"," <tr>\n"," <th>1275</th>\n"," <td>SaleID_1276</td>\n","
<td>Spain</td>\n"," <td>Sales visit</td>\n"," <td>Outdoors Shop</td>\n","
<td>Camping Equipment</td>\n"," <td>Tools</td>\n"," <td>Granite
Extreme</td>\n"," <td>2020.0</td>\n"," <td>Q3 2020</td>\n","
<td>89427.00</td>\n"," <td>1178.0</td>\n"," <td>0.386895</td>\n","
</tr>\n"," </tbody>\n","</table>\n","</div>\n"," <div class=\"colab-df-
buttons\">\n","\n"," <div class=\"colab-df-container\">\n"," <button
class=\"colab-df-convert\" onclick=\"convertToInteractive('df-6ac69492-9c4f-498a-
a6c1-ef49b29afb09')\"\n"," title=\"Convert this dataframe to an
interactive table.\"\n"," style=\"display:none;\">\n","\n"," <svg
xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\
n"," <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-
160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-
160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n"," </svg>\
n"," </button>\n","\n"," <style>\n"," .colab-df-container {\n","
display:flex;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n","
background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\
n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n","
height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\
n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n","
box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67,
0.15);\n"," fill: #174EA6;\n"," }\n","\n"," .colab-df-buttons div {\n","
margin-bottom: 4px;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n","
background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n","
[theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n","
box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px
1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\
n","\n"," <script>\n"," const buttonEl =\n","
document.querySelector('#df-6ac69492-9c4f-498a-a6c1-ef49b29afb09 button.colab-df-
convert');\n"," buttonEl.style.display =\n","
google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function
convertToInteractive(key) {\n"," const element =
document.querySelector('#df-6ac69492-9c4f-498a-a6c1-ef49b29afb09');\n","
const dataTable =\n"," await
google.colab.kernel.invokeFunction('convertToInteractive',\n","
[key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml
= 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\"
href=https://colab.research.google.com/notebooks/data_table.ipynb>data table
notebook</a>'\n"," + ' to learn more about interactive tables.';\n","
element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n","
await google.colab.output.renderOutput(dataTable, element);\n"," const
docLink = document.createElement('div');\n"," docLink.innerHTML =
docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n","
</script>\n"," </div>\n","\n","\n","<div id=\"df-49f51a65-8345-4d78-8955-
d5dead44add7\">\n"," <button class=\"colab-df-quickchart\"
onclick=\"quickchart('df-49f51a65-8345-4d78-8955-d5dead44add7')\"\n","
title=\"Suggest charts\"\n"," style=\"display:none;\">\n","\n","<svg
xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n","
width=\"24px\">\n"," <g>\n"," <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0
1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-
2v-4h2v4z\"/>\n"," </g>\n","</svg>\n"," </button>\n","\n","<style>\
n"," .colab-df-quickchart {\n"," --bg-color: #E8F0FE;\n"," --fill-color:
#1967D2;\n"," --hover-bg-color: #E2EBFA;\n"," --hover-fill-color:
#174EA6;\n"," --disabled-fill-color: #AAA;\n"," --disabled-bg-color:
#DDD;\n"," }\n","\n"," [theme=dark] .colab-df-quickchart {\n"," --bg-color:
#3B4455;\n"," --fill-color: #D2E3FC;\n"," --hover-bg-color: #434B5C;\n","
--hover-fill-color: #FFFFFF;\n"," --disabled-bg-color: #3B4455;\n"," --
disabled-fill-color: #666;\n"," }\n","\n"," .colab-df-quickchart {\n","
background-color: var(--bg-color);\n"," border: none;\n"," border-radius:
50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: var(--fill-
color);\n"," height: 32px;\n"," padding: 0;\n"," width: 32px;\n"," }\
n","\n"," .colab-df-quickchart:hover {\n"," background-color: var(--hover-bg-
color);\n"," box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60,
64, 67, 0.15);\n"," fill: var(--button-hover-fill-color);\n"," }\n","\
n"," .colab-df-quickchart-complete:disabled,\n"," .colab-df-quickchart-
complete:disabled:hover {\n"," background-color: var(--disabled-bg-color);\n","
fill: var(--disabled-fill-color);\n"," box-shadow: none;\n"," }\n","\
n"," .colab-df-spinner {\n"," border: 2px solid var(--fill-color);\n","
border-color: transparent;\n"," border-bottom-color: var(--fill-color);\n","
animation:\n"," spin 1s steps(1) infinite;\n"," }\n","\n"," @keyframes spin
{\n"," 0% {\n"," border-color: transparent;\n"," border-bottom-color:
var(--fill-color);\n"," border-left-color: var(--fill-color);\n"," }\n","
20% {\n"," border-color: transparent;\n"," border-left-color: var(--fill-
color);\n"," border-top-color: var(--fill-color);\n"," }\n"," 30% {\n","
border-color: transparent;\n"," border-left-color: var(--fill-color);\n","
border-top-color: var(--fill-color);\n"," border-right-color: var(--fill-
color);\n"," }\n"," 40% {\n"," border-color: transparent;\n","
border-right-color: var(--fill-color);\n"," border-top-color: var(--fill-
color);\n"," }\n"," 60% {\n"," border-color: transparent;\n","
border-right-color: var(--fill-color);\n"," }\n"," 80% {\n"," border-
color: transparent;\n"," border-right-color: var(--fill-color);\n","
border-bottom-color: var(--fill-color);\n"," }\n"," 90% {\n"," border-
color: transparent;\n"," border-bottom-color: var(--fill-color);\n"," }\
n"," }\n","</style>\n","\n"," <script>\n"," async function quickchart(key) {\
n"," const quickchartButtonEl =\n"," document.querySelector('#' + key +
' button');\n"," quickchartButtonEl.disabled = true; // To prevent multiple
clicks.\n"," quickchartButtonEl.classList.add('colab-df-spinner');\n","
try {\n"," const charts = await google.colab.kernel.invokeFunction(\n","
'suggestCharts', [key], {});\n"," } catch (error) {\n","
console.error('Error during call to suggestCharts:', error);\n"," }\n","
quickchartButtonEl.classList.remove('colab-df-spinner');\n","
quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n"," }\n","
(() => {\n"," let quickchartButtonEl =\n","
document.querySelector('#df-49f51a65-8345-4d78-8955-d5dead44add7 button');\n","
quickchartButtonEl.style.display =\n"," google.colab.kernel.accessAllowed ?
'block' : 'none';\n"," })();\n"," </script>\n","</div>\n","\n"," </div>\n","
</div>\n"],"application/vnd.google.colaboratory.intrinsic+json":
{"type":"dataframe","summary":"{\n \"name\": \"sales_products_data\",\n \"rows\":
5,\n \"fields\": [\n {\n \"column\": \"SaleID\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 5,\
n \"samples\": [\n \"SaleID_1273\",\n \"SaleID_1276\",\n
\"SaleID_1274\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"RetailerCountry\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Spain\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"OrderMethod\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Sales visit\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"RetailerType\",\n \"properties\": {\n \"dtype\":
\"category\",\n \"num_unique_values\": 1,\n \"samples\": [\n
\"Outdoors Shop\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n
}\n },\n {\n \"column\": \"ProductLine\",\n \"properties\": {\n
\"dtype\": \"string\",\n \"num_unique_values\": 3,\n \"samples\": [\n
\"Personal Accessories\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"ProductType\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 3,\
n \"samples\": [\n \"Rope\"\n ],\n \"semantic_type\":
\"\",\n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Product\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 5,\
n \"samples\": [\n \"Firefly Climbing Lamp\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Year\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 0.0,\n \"min\": 2020.0,\n
\"max\": 2020.0,\n \"num_unique_values\": 1,\n \"samples\": [\n
2020.0\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Quarter\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Q3 2020\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Revenue\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 33971.97864494324,\
n \"min\": 7536.29,\n \"max\": 89427.0,\
n \"num_unique_values\": 5,\n \"samples\": [\n 7536.29\n
],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\
n },\n {\n \"column\": \"Quantity\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 624.6172427975392,\
n \"min\": 173.0,\n \"max\": 1472.0,\n \"num_unique_values\":
5,\n \"samples\": [\n 193.0\n ],\n \"semantic_type\":
\"\",\n \"description\": \"\"\n }\n },\n {\
n \"column\": \"GrossMargin\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 0.10248931743254383,\
n \"min\": 0.29811357,\n \"max\": 0.56842037,\
n \"num_unique_values\": 5,\n \"samples\": [\n 0.44528732\n
],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\
n }\n ]\n}"}},"metadata":{},"execution_count":140}],"source":
["sales_products_data.tail()"]},{"cell_type":"markdown","source":["The value I get
is 0.38689474 but the tail() function is giving the rounded version i.e.,
0.386895,but it's the same."],"metadata":{"id":"3bpyOFGbB3EK"}},
{"cell_type":"markdown","metadata":{"id":"cUqCsleDZhc3"},"source":["Prove that
**.iloc[]** can be applied to a Series object such as
**sales_products_data['Product']** as well (e.g. by obtaining the first element
from this column).\n","<br><br> *Note: We are asking you to try this syntax out to
make sure you are in control of obtaining the desired portion of the data
regardless of the object it has been contained into. The syntax and tools are
similar, while their utilization may differ.*\n","<br> *This note applies to this
and the next task.*"]},{"cell_type":"code","execution_count":null,"metadata":
{"id":"FeW_42wDZhc3","colab":{"base_uri":"https://
localhost:8080/","height":35},"executionInfo":
{"status":"ok","timestamp":1733926078115,"user_tz":-300,"elapsed":541,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"c4ca1740-a21d-4fcb-ed10-
5328aa0f30c1"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["'TrailChef Deluxe Cook
Set'"],"application/vnd.google.colaboratory.intrinsic+json":
{"type":"string"}},"metadata":{},"execution_count":144}],"source":
["sales_products_data['Product'].iloc[0]"]},{"cell_type":"code","source":
["sales_products_data.head(1)"],"metadata":{"colab":{"base_uri":"https://
localhost:8080/","height":135},"id":"vyyHA76mDJO2","executionInfo":
{"status":"ok","timestamp":1733926113586,"user_tz":-300,"elapsed":476,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"14267628-8e17-4d6b-a5b0-
f6d21a9efe4a"},"execution_count":null,"outputs":
[{"output_type":"execute_result","data":{"text/plain":[" SaleID RetailerCountry
OrderMethod RetailerType ProductLine \\\n","0 SaleID_1 United
States Fax Outdoors Shop Personal Accessories \n","\n"," ProductType
Product Year Quarter Revenue \\\n","0 Cooking Gear TrailChef Deluxe Cook
Set 2018.0 Q1 2018 59728.66 \n","\n"," Quantity GrossMargin \n","0
491.0 0.357548 "],"text/html":["\n"," <div id=\"df-9a4f51a8-e016-4211-8a78-
b0afde917204\" class=\"colab-df-container\">\n"," <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>SaleID</th>\
n"," <th>RetailerCountry</th>\n"," <th>OrderMethod</th>\n","
<th>RetailerType</th>\n"," <th>ProductLine</th>\n","
<th>ProductType</th>\n"," <th>Product</th>\n"," <th>Year</th>\n","
<th>Quarter</th>\n"," <th>Revenue</th>\n"," <th>Quantity</th>\n","
<th>GrossMargin</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n","
<th>0</th>\n"," <td>SaleID_1</td>\n"," <td>United States</td>\n","
<td>Fax</td>\n"," <td>Outdoors Shop</td>\n"," <td>Personal
Accessories</td>\n"," <td>Cooking Gear</td>\n"," <td>TrailChef Deluxe
Cook Set</td>\n"," <td>2018.0</td>\n"," <td>Q1 2018</td>\n","
<td>59728.66</td>\n"," <td>491.0</td>\n"," <td>0.357548</td>\n","
</tr>\n"," </tbody>\n","</table>\n","</div>\n"," <div class=\"colab-df-
buttons\">\n","\n"," <div class=\"colab-df-container\">\n"," <button
class=\"colab-df-convert\" onclick=\"convertToInteractive('df-9a4f51a8-e016-4211-
8a78-b0afde917204')\"\n"," title=\"Convert this dataframe to an
interactive table.\"\n"," style=\"display:none;\">\n","\n"," <svg
xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\
n"," <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-
160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-
160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n"," </svg>\
n"," </button>\n","\n"," <style>\n"," .colab-df-container {\n","
display:flex;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n","
background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\
n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n","
height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\
n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n","
box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67,
0.15);\n"," fill: #174EA6;\n"," }\n","\n"," .colab-df-buttons div {\n","
margin-bottom: 4px;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n","
background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n","
[theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n","
box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px
1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\
n","\n"," <script>\n"," const buttonEl =\n","
document.querySelector('#df-9a4f51a8-e016-4211-8a78-b0afde917204 button.colab-df-
convert');\n"," buttonEl.style.display =\n","
google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function
convertToInteractive(key) {\n"," const element =
document.querySelector('#df-9a4f51a8-e016-4211-8a78-b0afde917204');\n","
const dataTable =\n"," await
google.colab.kernel.invokeFunction('convertToInteractive',\n","
[key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml
= 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\"
href=https://colab.research.google.com/notebooks/data_table.ipynb>data table
notebook</a>'\n"," + ' to learn more about interactive tables.';\n","
element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n","
await google.colab.output.renderOutput(dataTable, element);\n"," const
docLink = document.createElement('div');\n"," docLink.innerHTML =
docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n","
</script>\n"," </div>\n","\n","\n"," </div>\n","
</div>\n"],"application/vnd.google.colaboratory.intrinsic+json":
{"type":"dataframe","variable_name":"sales_products_data","summary":"{\n \"name\":
\"sales_products_data\",\n \"rows\": 1276,\n \"fields\": [\n {\
n \"column\": \"SaleID\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1276,\
n \"samples\": [\n \"SaleID_102\",\n \"SaleID_52\",\n
\"SaleID_77\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"RetailerCountry\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 21,\
n \"samples\": [\n
\"United States\",\n \"Germany\",\n \"Finland\"\
n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n
}\n },\n {\n \"column\": \"OrderMethod\",\n \"properties\": {\n
\"dtype\": \"category\",\n \"num_unique_values\": 7,\n \"samples\":
[\n \"Fax\",\n \"Phone\",\n \"Other\"\n ],\n
\"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n
\"column\": \"RetailerType\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 8,\
n \"samples\": [\n \"Mall\",\n \"Discount Retailer\",\n
\"Outdoors Shop\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"ProductLine\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 5,\
n \"samples\": [\n \"Sports Equipment\",\n \"Outdoor
Protection\",\n \"Camping Equipment\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"ProductType\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 21,\
n \"samples\": [\n \"Cooking Gear\",\n \"Putters\",\n
\"Navigation\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Product\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 143,\
n \"samples\": [\n \"Star Gazer 6\",\n \"Granite Climbing
Helmet\",\n \"EverGlow Lamp\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Year\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 0.7175962927121285,\
n \"min\": 2018.0,\n \"max\": 2020.0,\n \"num_unique_values\":
3,\n \"samples\": [\n 2018.0,\n 2019.0,\n 2020.0\
n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n
}\n },\n {\n \"column\": \"Quarter\",\n \"properties\": {\
n \"dtype\": \"category\",\n \"num_unique_values\": 10,\
n \"samples\": [\n \"Q2 2020\",\n \"Q2 2018\",\
n \"Q3 2019\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Revenue\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 51124.45062498806,\
n \"min\": 0.0,\n \"max\": 944436.75,\n \"num_unique_values\":
1241,\n \"samples\": [\n 12754.32,\n 36648.64,\n
5680.05\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Quantity\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 977.7235161907016,\
n \"min\": 1.0,\n \"max\": 13758.0,\n \"num_unique_values\":
723,\n \"samples\": [\n 251.0,\n 358.0,\n 3556.0\
n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n
}\n },\n {\n \"column\": \"GrossMargin\",\n \"properties\": {\n
\"dtype\": \"number\",\n \"std\": 0.11257501207480596,\n \"min\":
0.05870851,\n \"max\": 0.78047619,\n \"num_unique_values\": 691,\n
\"samples\": [\n 0.49066667,\n 0.48346215,\n 0.64469388\
n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n
}\n }\n ]\n}"}},"metadata":{},"execution_count":145}]},
{"cell_type":"markdown","source":["As we can see iloc[] successfully accessed first
element from the \"Product\" feature.So it can be applied to series as
well."],"metadata":{"id":"fc3tPxslDPuF"}},{"cell_type":"markdown","metadata":
{"id":"QmBWTzkQZhc3"},"source":["Although we are not advised to, when working with
a Series object, we can obtain the same output without using the **.iloc[]**
indexer and using \"classical\" Python indexing. Can you try that out?"]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"l4irNIj7Zhc4","colab":
{"base_uri":"https://localhost:8080/","height":35},"executionInfo":
{"status":"ok","timestamp":1733926316557,"user_tz":-300,"elapsed":2018,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"c6556fab-f86c-4983-b9cd-
277128d534e1"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["'TrailChef Deluxe Cook
Set'"],"application/vnd.google.colaboratory.intrinsic+json":
{"type":"string"}},"metadata":{},"execution_count":146}],"source":
["sales_products_data[\"Product\"][0]"]},{"cell_type":"markdown","metadata":
{"id":"Pxab0iKQZhc4"},"source":["## pandas DataFrames - Indexing with .loc[]"]},
{"cell_type":"markdown","metadata":{"id":"EclI2IvUZhc4"},"source":["Retrieve the
values from the first row of the DataFrame by using the specified label-based index
rather than the default numeric index."]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"TuWPOQ6cZhc5","colab":
{"base_uri":"https://localhost:8080/","height":135},"executionInfo":
{"status":"ok","timestamp":1733926691609,"user_tz":-300,"elapsed":613,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"c6f4af6d-059c-4955-d359-
f788bb0ee7d6"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["
SaleID RetailerCountry OrderMethod RetailerType ProductLine \\\n","0
SaleID_1 United States Fax Outdoors Shop Personal Accessories \n","\
n"," ProductType Product Year Quarter Revenue \\\n","0
Cooking Gear TrailChef Deluxe Cook Set 2018.0 Q1 2018 59728.66 \n","\n","
Quantity GrossMargin \n","0 491.0 0.357548 "],"text/html":["\n"," <div
id=\"df-8ed7275d-1e70-4de4-8f21-f7af2f15d273\" class=\"colab-df-container\">\n","
<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>SaleID</th>\n"," <th>RetailerCountry</th>\n"," <th>OrderMethod</th>\
n"," <th>RetailerType</th>\n"," <th>ProductLine</th>\n","
<th>ProductType</th>\n"," <th>Product</th>\n"," <th>Year</th>\n","
<th>Quarter</th>\n"," <th>Revenue</th>\n"," <th>Quantity</th>\n","
<th>GrossMargin</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n","
<th>0</th>\n"," <td>SaleID_1</td>\n"," <td>United States</td>\n","
<td>Fax</td>\n"," <td>Outdoors Shop</td>\n"," <td>Personal
Accessories</td>\n"," <td>Cooking Gear</td>\n"," <td>TrailChef Deluxe
Cook Set</td>\n"," <td>2018.0</td>\n"," <td>Q1 2018</td>\n","
<td>59728.66</td>\n"," <td>491.0</td>\n"," <td>0.357548</td>\n","
</tr>\n"," </tbody>\n","</table>\n","</div>\n"," <div class=\"colab-df-
buttons\">\n","\n"," <div class=\"colab-df-container\">\n"," <button
class=\"colab-df-convert\" onclick=\"convertToInteractive('df-8ed7275d-1e70-4de4-
8f21-f7af2f15d273')\"\n"," title=\"Convert this dataframe to an
interactive table.\"\n"," style=\"display:none;\">\n","\n"," <svg
xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\
n"," <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-
160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-
160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n"," </svg>\
n"," </button>\n","\n"," <style>\n"," .colab-df-container {\n","
display:flex;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n","
background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\
n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n","
height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\
n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n","
box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67,
0.15);\n"," fill: #174EA6;\n"," }\n","\n"," .colab-df-buttons div {\n","
margin-bottom: 4px;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n","
background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n","
[theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n","
box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px
1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\
n","\n"," <script>\n"," const buttonEl =\n","
document.querySelector('#df-8ed7275d-1e70-4de4-8f21-f7af2f15d273 button.colab-df-
convert');\n"," buttonEl.style.display =\n","
google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function
convertToInteractive(key) {\n"," const element =
document.querySelector('#df-8ed7275d-1e70-4de4-8f21-f7af2f15d273');\n","
const dataTable =\n"," await
google.colab.kernel.invokeFunction('convertToInteractive',\n","
[key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml
= 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\"
href=https://colab.research.google.com/notebooks/data_table.ipynb>data
table notebook</a>'\n"," + ' to learn more about interactive tables.';\
n"," element.innerHTML = '';\n"," dataTable['output_type'] =
'display_data';\n"," await google.colab.output.renderOutput(dataTable,
element);\n"," const docLink = document.createElement('div');\n","
docLink.innerHTML = docLinkHtml;\n"," element.appendChild(docLink);\n","
}\n"," </script>\n"," </div>\n","\n","\n"," </div>\n"," </div>\
n"],"application/vnd.google.colaboratory.intrinsic+json":
{"type":"dataframe","summary":"{\n \"name\": \"sales_products_data\",\n \"rows\":
1,\n \"fields\": [\n {\n \"column\": \"SaleID\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"SaleID_1\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"RetailerCountry\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"United States\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"OrderMethod\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Fax\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"RetailerType\",\n \"properties\": {\n \"dtype\":
\"string\",\n \"num_unique_values\": 1,\n \"samples\": [\
n \"Outdoors Shop\"\n ],\n \"semantic_type\": \"\",\n
\"description\": \"\"\n }\n },\n {\n \"column\": \"ProductLine\",\n
\"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\":
1,\n \"samples\": [\n \"Personal Accessories\"\n ],\n
\"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n
\"column\": \"ProductType\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Cooking Gear\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Product\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"TrailChef Deluxe Cook Set\"\n ],\n
\"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n
\"column\": \"Year\",\n \"properties\": {\n \"dtype\": \"number\",\n
\"std\": null,\n \"min\": 2018.0,\n \"max\": 2018.0,\
n \"num_unique_values\": 1,\n \"samples\": [\n 2018.0\n
],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\
n },\n {\n \"column\": \"Quarter\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 1,\
n \"samples\": [\n \"Q1 2018\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Revenue\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": null,\n \"min\":
59728.66,\n \"max\": 59728.66,\n \"num_unique_values\": 1,\
n \"samples\": [\n 59728.66\n ],\n \"semantic_type\":
\"\",\n \"description\": \"\"\n }\n },\n {\
n \"column\": \"Quantity\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": null,\n \"min\": 491.0,\n
\"max\": 491.0,\n \"num_unique_values\": 1,\n \"samples\": [\n
491.0\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\
n }\n },\n {\n \"column\": \"GrossMargin\",\n \"properties\":
{\n \"dtype\": \"number\",\n \"std\": null,\n \"min\":
0.35754797,\n \"max\": 0.35754797,\n \"num_unique_values\": 1,\n
\"samples\": [\n 0.35754797\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n }\n ]\n}"}},"metadata":
{},"execution_count":151}],"source":["sales_products_data.loc[0:0]"]},
{"cell_type":"markdown","metadata":{"id":"XTCyknZnZhc5"},"source":["By using the
specified label-based index again, retrieve the information stored in the
'GrossMargin' column for the 4th sale."]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"qpKXR01EZhc5","colab":
{"base_uri":"https://localhost:8080/"},"executionInfo":
{"status":"ok","timestamp":1733926776637,"user_tz":-300,"elapsed":526,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"445e3152-f07a-47ce-fa57-
a5f8dded94fb"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["0.29293788"]},"metadata":{},"execution_count":152}],"source":
["sales_products_data[\"GrossMargin\"].loc[3]"]},
{"cell_type":"markdown","metadata":{"id":"YK-abvhUZhc6"},"source":["Obtain a
DataFrame containg the values stored in all columns for sales numbered 15, 235, and
1147 by using the **.loc[]** indexer."]},
{"cell_type":"code","execution_count":null,"metadata":{"id":"57KyhSwVZhc6","colab":
{"base_uri":"https://localhost:8080/","height":216},"executionInfo":
{"status":"ok","timestamp":1733927096193,"user_tz":-300,"elapsed":546,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"e159b12e-e4dc-4da8-f942-
26ec0cbdaf81"},"outputs":[{"output_type":"execute_result","data":{"text/plain":["
SaleID RetailerCountry OrderMethod RetailerType \\\n","15 SaleID_16
United States Web Mall \n","235 SaleID_236
Mexico Web Mall \n","1147 SaleID_1148 Germany
Phone Department Store \n","\n"," ProductLine ProductType
Product Year Quarter Revenue \\\n","15 Camping Equipment Knives
Max Gizmo 2018.0 Q1 2018 12362.20 \n","235 Camping Equipment Binoculars
Ranger Vision 2018.0 Q3 2018 5700.00 \n","1147 Camping Equipment Lanterns
EverGlow Lamp 2020.0 Q1 2020 44998.55 \n","\n"," Quantity GrossMargin \
n","15 323.0 0.549791 \n","235 37.0 0.370000 \n","1147
1670.0 0.524364 "],"text/html":["\n"," <div id=\"df-88fe51a3-1606-48c0-a115-
43c8617ff768\" class=\"colab-df-container\">\n"," <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>SaleID</th>\
n"," <th>RetailerCountry</th>\n"," <th>OrderMethod</th>\n","
<th>RetailerType</th>\n"," <th>ProductLine</th>\n","
<th>ProductType</th>\n"," <th>Product</th>\n"," <th>Year</th>\n","
<th>Quarter</th>\n"," <th>Revenue</th>\n"," <th>Quantity</th>\n","
<th>GrossMargin</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n","
<th>15</th>\n"," <td>SaleID_16</td>\n"," <td>United States</td>\n","
<td>Web</td>\n"," <td>Mall</td>\n"," <td>Camping Equipment</td>\n","
<td>Knives</td>\n"," <td>Max Gizmo</td>\n"," <td>2018.0</td>\n","
<td>Q1 2018</td>\n"," <td>12362.20</td>\n"," <td>323.0</td>\n","
<td>0.549791</td>\n"," </tr>\n"," <tr>\n"," <th>235</th>\n","
<td>SaleID_236</td>\n"," <td>Mexico</td>\n"," <td>Web</td>\n","
<td>Mall</td>\n"," <td>Camping Equipment</td>\n"," <td>Binoculars</td>\
n"," <td>Ranger Vision</td>\n"," <td>2018.0</td>\n"," <td>Q3
2018</td>\n"," <td>5700.00</td>\n"," <td>37.0</td>\n","
<td>0.370000</td>\n"," </tr>\n"," <tr>\n"," <th>1147</th>\n","
<td>SaleID_1148</td>\n"," <td>Germany</td>\n"," <td>Phone</td>\n","
<td>Department Store</td>\n"," <td>Camping Equipment</td>\n","
<td>Lanterns</td>\n"," <td>EverGlow Lamp</td>\n"," <td>2020.0</td>\n","
<td>Q1 2020</td>\n"," <td>44998.55</td>\n"," <td>1670.0</td>\n","
<td>0.524364</td>\n"," </tr>\n"," </tbody>\n","</table>\n","</div>\n"," <div
class=\"colab-df-buttons\">\n","\n"," <div class=\"colab-df-container\">\n","
<button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-88fe51a3-
1606-48c0-a115-43c8617ff768')\"\n"," title=\"Convert this dataframe to
an interactive table.\"\n"," style=\"display:none;\">\n","\n"," <svg
xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\
n"," <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-
160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-
160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n"," </svg>\
n"," </button>\n","\n"," <style>\n"," .colab-df-container {\n","
display:flex;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n","
background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\
n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n","
height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\
n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n","
box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67,
0.15);\n"," fill: #174EA6;\n"," }\n","\n"," .colab-df-buttons div {\n","
margin-bottom: 4px;\n","
}\n","\n"," [theme=dark] .colab-df-convert {\n"," background-color:
#3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n"," [theme=dark] .colab-df-
convert:hover {\n"," background-color: #434B5C;\n"," box-shadow: 0px 1px
3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px 1px 2px rgba(0, 0,
0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\n","\n"," <script>\
n"," const buttonEl =\n"," document.querySelector('#df-88fe51a3-1606-
48c0-a115-43c8617ff768 button.colab-df-convert');\n"," buttonEl.style.display
=\n"," google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n","
async function convertToInteractive(key) {\n"," const element =
document.querySelector('#df-88fe51a3-1606-48c0-a115-43c8617ff768');\n","
const dataTable =\n"," await
google.colab.kernel.invokeFunction('convertToInteractive',\n","
[key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml
= 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\"
href=https://colab.research.google.com/notebooks/data_table.ipynb>data table
notebook</a>'\n"," + ' to learn more about interactive tables.';\n","
element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n","
await google.colab.output.renderOutput(dataTable, element);\n"," const
docLink = document.createElement('div');\n"," docLink.innerHTML =
docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n","
</script>\n"," </div>\n","\n","\n","<div id=\"df-c3e32222-7263-4b84-8c67-
b128c5b7b5ad\">\n"," <button class=\"colab-df-quickchart\"
onclick=\"quickchart('df-c3e32222-7263-4b84-8c67-b128c5b7b5ad')\"\n","
title=\"Suggest charts\"\n"," style=\"display:none;\">\n","\n","<svg
xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n","
width=\"24px\">\n"," <g>\n"," <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0
1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-
2v-4h2v4z\"/>\n"," </g>\n","</svg>\n"," </button>\n","\n","<style>\
n"," .colab-df-quickchart {\n"," --bg-color: #E8F0FE;\n"," --fill-color:
#1967D2;\n"," --hover-bg-color: #E2EBFA;\n"," --hover-fill-color:
#174EA6;\n"," --disabled-fill-color: #AAA;\n"," --disabled-bg-color:
#DDD;\n"," }\n","\n"," [theme=dark] .colab-df-quickchart {\n"," --bg-color:
#3B4455;\n"," --fill-color: #D2E3FC;\n"," --hover-bg-color: #434B5C;\n","
--hover-fill-color: #FFFFFF;\n"," --disabled-bg-color: #3B4455;\n"," --
disabled-fill-color: #666;\n"," }\n","\n"," .colab-df-quickchart {\n","
background-color: var(--bg-color);\n"," border: none;\n"," border-radius:
50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: var(--fill-
color);\n"," height: 32px;\n"," padding: 0;\n"," width: 32px;\n"," }\
n","\n"," .colab-df-quickchart:hover {\n"," background-color: var(--hover-bg-
color);\n"," box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60,
64, 67, 0.15);\n"," fill: var(--button-hover-fill-color);\n"," }\n","\
n"," .colab-df-quickchart-complete:disabled,\n"," .colab-df-quickchart-
complete:disabled:hover {\n"," background-color: var(--disabled-bg-color);\n","
fill: var(--disabled-fill-color);\n"," box-shadow: none;\n"," }\n","\
n"," .colab-df-spinner {\n"," border: 2px solid var(--fill-color);\n","
border-color: transparent;\n"," border-bottom-color: var(--fill-color);\n","
animation:\n"," spin 1s steps(1) infinite;\n"," }\n","\n"," @keyframes spin
{\n"," 0% {\n"," border-color: transparent;\n"," border-bottom-color:
var(--fill-color);\n"," border-left-color: var(--fill-color);\n"," }\n","
20% {\n"," border-color: transparent;\n"," border-left-color: var(--fill-
color);\n"," border-top-color: var(--fill-color);\n"," }\n"," 30% {\n","
border-color: transparent;\n"," border-left-color: var(--fill-color);\n","
border-top-color: var(--fill-color);\n"," border-right-color: var(--fill-
color);\n"," }\n"," 40% {\n"," border-color: transparent;\n","
border-right-color: var(--fill-color);\n"," border-top-color: var(--fill-
color);\n"," }\n"," 60% {\n"," border-color: transparent;\n","
border-right-color: var(--fill-color);\n"," }\n"," 80% {\n"," border-
color: transparent;\n"," border-right-color: var(--fill-color);\n","
border-bottom-color: var(--fill-color);\n"," }\n"," 90% {\n"," border-
color: transparent;\n"," border-bottom-color: var(--fill-color);\n"," }\
n"," }\n","</style>\n","\n"," <script>\n"," async function quickchart(key) {\
n"," const quickchartButtonEl =\n"," document.querySelector('#' + key +
' button');\n"," quickchartButtonEl.disabled = true; // To prevent multiple
clicks.\n"," quickchartButtonEl.classList.add('colab-df-spinner');\n","
try {\n"," const charts = await google.colab.kernel.invokeFunction(\n","
'suggestCharts', [key], {});\n"," } catch (error) {\n","
console.error('Error during call to suggestCharts:', error);\n"," }\n","
quickchartButtonEl.classList.remove('colab-df-spinner');\n","
quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n"," }\n","
(() => {\n"," let quickchartButtonEl =\n","
document.querySelector('#df-c3e32222-7263-4b84-8c67-b128c5b7b5ad button');\n","
quickchartButtonEl.style.display =\n"," google.colab.kernel.accessAllowed ?
'block' : 'none';\n"," })();\n"," </script>\n","</div>\n","\n"," </div>\n","
</div>\n"],"application/vnd.google.colaboratory.intrinsic+json":
{"type":"dataframe","summary":"{\n \"name\": \"sales_products_data\",\n \"rows\":
3,\n \"fields\": [\n {\n \"column\": \"SaleID\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 3,\
n \"samples\": [\n \"SaleID_16\",\n \"SaleID_236\",\n
\"SaleID_1148\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"RetailerCountry\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 3,\
n \"samples\": [\n \"United States\",\n \"Mexico\",\n
\"Germany\"\n ],\n \"semantic_type\": \"\",\n \"description\":
\"\"\n }\n },\n {\n \"column\": \"OrderMethod\",\
n \"properties\": {\n \"dtype\": \"string\",\
n \"num_unique_values\": 2,\n \"samples\": [\n \"Phone\",\n
\"Web\"\n ],\n \"semantic_type\": \"\",\
n \"description\": \"\"\n }\n },\n {\
n \"column\": \"RetailerType\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 2,\
n \"samples\": [\n \"Department Store\",\n \"Mall\"\n
],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\
n },\n {\n \"column\": \"ProductLine\",\n \"properties\": {\n
\"dtype\": \"category\",\n \"num_unique_values\": 1,\n \"samples\":
[\n \"Camping Equipment\"\n ],\n \"semantic_type\": \"\",\n
\"description\": \"\"\n }\n },\n {\n \"column\": \"ProductType\",\n
\"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\":
3,\n \"samples\": [\n \"Knives\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Product\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 3,\
n \"samples\": [\n \"Max Gizmo\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Year\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 1.1547005383792515,\
n \"min\": 2018.0,\n \"max\": 2020.0,\n \"num_unique_values\":
2,\n \"samples\": [\n 2020.0\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Quarter\",\n \"properties\": {\
n \"dtype\": \"string\",\n \"num_unique_values\": 3,\
n \"samples\": [\n \"Q1 2018\"\n ],\
n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n
{\n \"column\": \"Revenue\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 21031.295261526335,\
n \"min\": 5700.0,\n \"max\": 44998.55,\
n \"num_unique_values\": 3,\n \"samples\": [\n 12362.2\n
],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\
n },\n {\n \"column\": \"Quantity\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 872.05638196927,\
n \"min\": 37.0,\n \"max\": 1670.0,\n \"num_unique_values\":
3,\n \"samples\": [\n 323.0\n ],\n \"semantic_type\":
\"\",\n \"description\": \"\"\n }\n },\n {\
n \"column\": \"GrossMargin\",\n \"properties\": {\
n \"dtype\": \"number\",\n \"std\": 0.09729631636418926,\
n \"min\": 0.37,\n \"max\": 0.54979058,\
n \"num_unique_values\": 3,\n \"samples\": [\n 0.54979058\n
],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\
n }\n ]\n}"}},"metadata":{},"execution_count":156}],"source":
["sales_products_data.loc[[15,235,1147]]"]},{"cell_type":"markdown","metadata":
{"id":"GqQXFBexZhc6"},"source":["With
the help of the **.loc[]** indexer, select the last 5 records from the 'Year'
column."]},{"cell_type":"code","execution_count":null,"metadata":
{"id":"vXmCgpvjZhc7","colab":{"base_uri":"https://
localhost:8080/","height":241},"executionInfo":
{"status":"ok","timestamp":1733927007473,"user_tz":-300,"elapsed":127,"user":
{"displayName":"Almas
Islam","userId":"05912423101588664233"}},"outputId":"25cd7598-c877-4cb1-d43f-
00cdde801e81"},"outputs":[{"output_type":"execute_result","data":{"text/plain":
["1271 2020.0\n","1272 2020.0\n","1273 2020.0\n","1274 2020.0\n","1275
2020.0\n","Name: Year, dtype: float64"],"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>Year</th>\n","
</tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>1271</th>\n","
<td>2020.0</td>\n"," </tr>\n"," <tr>\n"," <th>1272</th>\n","
<td>2020.0</td>\n"," </tr>\n"," <tr>\n"," <th>1273</th>\n","
<td>2020.0</td>\n"," </tr>\n"," <tr>\n"," <th>1274</th>\n","
<td>2020.0</td>\n"," </tr>\n"," <tr>\n"," <th>1275</th>\n","
<td>2020.0</td>\n"," </tr>\n","
</tbody>\n","</table>\n","</div><br><label><b>dtype:</b>
float64</label>"]},"metadata":{},"execution_count":155}],"source":
["sales_products_data[\"Year\"].loc[1271:1275]"]}],"metadata":{"anaconda-cloud":
{},"kernelspec":{"display_name":"Python 3
(ipykernel)","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.12.7"},"colab":{"provenance":
[{"file_id":"1CdJUUSRh8wacGVrhDbleteHCYIB9nKzI","timestamp":1733915240347}]}},"nbfo
rmat":4,"nbformat_minor":0}

You might also like