{ "cells": [ { "cell_type": "code", "execution_count": 27, "id": "3d7d3417", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: pandas...

1 answer below ยป
The tasks for this assignment is in the file. I do not have the attached files in pdf form or in Doc form


{ "cells": [ { "cell_type": "code", "execution_count": 27, "id": "3d7d3417", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: pandas in ./env/lib/python3.8/site-packages (1.2.5)\n", "Requirement already satisfied: python-dateutil>=2.7.3 in ./env/lib/python3.8/site-packages (from pandas) (2.8.1)\n", "Requirement already satisfied: numpy>=1.16.5 in ./env/lib/python3.8/site-packages (from pandas) (1.21.0)\n", "Requirement already satisfied: pytz>=2017.3 in ./env/lib/python3.8/site-packages (from pandas) (2021.1)\n", "Requirement already satisfied: six>=1.5 in ./env/lib/python3.8/site-packages (from python-dateutil>=2.7.3->pandas) (1.16.0)\n", "Requirement already satisfied: numpy in ./env/lib/python3.8/site-packages (1.21.0)\n", "Requirement already satisfied: matplotlib in ./env/lib/python3.8/site-packages (3.4.2)\n", "Requirement already satisfied: python-dateutil>=2.7 in ./env/lib/python3.8/site-packages (from matplotlib) (2.8.1)\n", "Requirement already satisfied: numpy>=1.16 in ./env/lib/python3.8/site-packages (from matplotlib) (1.21.0)\n", "Requirement already satisfied: cycler>=0.10 in ./env/lib/python3.8/site-packages (from matplotlib) (0.10.0)\n", "Requirement already satisfied: kiwisolver>=1.0.1 in ./env/lib/python3.8/site-packages (from matplotlib) (1.3.1)\n", "Requirement already satisfied: pyparsing>=2.2.1 in ./env/lib/python3.8/site-packages (from matplotlib) (2.4.7)\n", "Requirement already satisfied: pillow>=6.2.0 in ./env/lib/python3.8/site-packages (from matplotlib) (8.2.0)\n", "Requirement already satisfied: six in ./env/lib/python3.8/site-packages (from cycler>=0.10->matplotlib) (1.16.0)\n" ] } ], "source": [ "import sys\n", "!{sys.executable} -m pip install pandas\n", "!{sys.executable} -m pip install numpy\n", "!{sys.executable} -m pip install matplotlib" ] }, { "cell_type": "code", "execution_count": 116, "id": "bca30f2e", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 135, "id": "537ab953", "metadata": {}, "outputs": [], "source": [ "# The file contains 10 most popular baby names from 2017 to 2020. \n", "df = pd.read_csv(\"name_data_2017_2020.csv\")" ] }, { "cell_type": "code", "execution_count": 136, "id": "6dddb58e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\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", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "














































NameSexFrequencyYear
0OliviaF175352020
1EmmaF155812020
2AvaF130842020
3CharlotteF130032020
4SophiaF129762020
\n", "
" ], "text/plain": [ " Name Sex Frequency Year\n", "0 Olivia F 17535 2020\n", "1 Emma F 15581 2020\n", "2 Ava F 13084 2020\n", "3 Charlotte F 13003 2020\n", "4 Sophia F 12976 2020" ] }, "execution_count": 136, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.head() # Shows the first 5 rows from the input_data" ] }, { "cell_type": "code", "execution_count": 137, "id": "6696edda", "metadata": {}, "outputs": [], "source": [ "### YOUR TASK HERE\n", "# Show only the first 3 rows from the input_data\n", "\n", "# Your code here\n", "\n" ] }, { "cell_type": "code", "execution_count": 138, "id": "cd123398", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\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"
Answered Same DayJul 02, 2021

Answer To: { "cells": [ { "cell_type": "code", "execution_count": 27, "id": "3d7d3417", "metadata": {},...

Pritam Kumar answered on Jul 02 2021
155 Votes
{
"cells": [
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Requirement already satisfied: pandas in ./env/lib/python3.8/site-packages (1.2.5)\n",
"Requirement already satisfied: python-dateutil>=2.7.3 in ./env/lib/python3.8/site-packages (from pandas) (2.8.1)\n",
"Requirement already satisfied: numpy>=1.16.5 in ./env/lib/python3.8/site-packages (from pandas) (1.21.0)\n",
"Requirement already satisfied: pytz>=2017.3 in ./env/lib/python3.8/site-packages (from pandas) (2021.1)\n",
"Requirement already satisfied: six>=1.5 in ./env/lib/python3.8/site-packages (from python-dateutil>=2.7.3->pandas) (1.16.0)\n",
"Requirement already satisfied: numpy in ./env/lib/python3.8/site-packages (1.21.0)\n",
"Requirement already satisfied: matplotlib in ./env/lib/python3.8/site-packages (3.4.2)\n",
"Requirement already satisfied: python-dateutil>=2.7 in ./env/lib/python3.8/site-packages (from matplotlib) (2.8.1)\n",
"Requirement already satisfied: numpy>=1.16 in ./env/lib/python3.8/site-packages (from matplotlib) (1.21.0)\n",
"Requirement already satisfied: cycler>=0.10 in ./env/lib/python3.8/site-packages (from matplotlib) (0.10.0)\n",
"Requirement already satisfied: kiwisolver>=1.0.1 in ./env/lib/python3.8/site-packages (from matplotlib) (1.3.1)\n",
"Requirement already satisfied: pyparsing>=2.2.1 in ./env/lib/python3.8/site-packages (from matplotlib) (2.4.7)\n",
"Requirement already satisfied: pillow>=6.2.0 in ./env/lib/python3.8/site-packages (from matplotlib) (8.2.0)\n",
"Requirement already satisfied: six in ./env/lib/python3.8/site-packages (from cycler>=0.10->matplotlib) (1.16.0
)\n"
]
}
],
"source": [
"import sys\n",
"!{sys.executable} -m pip install pandas\n",
"!{sys.executable} -m pip install numpy\n",
"!{sys.executable} -m pip install matplotlib"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"# The file contains 10 most popular baby names from 2017 to 2020. \n",
"df = pd.read_csv('D:/name_data_2017_2020.csv')"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
NameSexFrequencyYear
0OliviaF175352020
1EmmaF155812020
2AvaF130842020
3CharlotteF130032020
4SophiaF129762020
\n",
"
"
],
"text/plain": [
" Name Sex Frequency Year\n",
"0 Olivia F 17535 2020\n",
"1 Emma F 15581 2020\n",
"2 Ava F 13084 2020\n",
"3 Charlotte F 13003 2020\n",
"4 Sophia F 12976 2020"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head() # Shows the first 5 rows from the input_data"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
NameSexFrequencyYear
0OliviaF175352020
1EmmaF155812020
2AvaF130842020
\n",
"
"
],
"text/plain": [
" Name Sex Frequency Year\n",
"0 Olivia F 17535 2020\n",
"1 Emma F 15581 2020\n",
"2 Ava F 13084 2020"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"### YOUR TASK HERE\n",
"# Show only the first 3 rows from the input_data\n",
"\n",
"df.head(3)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
NameSexFrequencyYear
75BenjaminM138382017
76MasonM135642017
77ElijahM133882017
78JacobM132192017
79OliverM132122017
\n",
"
"
],
"text/plain": [
" Name Sex Frequency Year\n",
"75 Benjamin M 13838 2017\n",
"76 Mason M 13564 2017\n",
"77 Elijah M 13388 2017\n",
"78 Jacob M 13219 2017\n",
"79 Oliver M 13212 2017"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.tail() # Shows the last 5 rows from the input_data"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 Olivia\n",
"1 Emma\n",
"2 Ava\n",
"3 Charlotte\n",
"4 Sophia\n",
"5 Amelia\n",
"6 Isabella\n",
"7 Mia\n",
"8 Evelyn\n",
"9 Harper\n",
"10 Liam\n",
"11 Noah\n",
"12 Oliver\n",
"13 Elijah\n",
"14 William\n",
"15 James\n",
"16 Benjamin\n",
"17 Lucas\n",
"18 Henry\n",
"19 Alexander\n",
"20 Olivia\n",
"21 Emma\n",
"22 Ava\n",
"23 Sophia\n",
"24 Isabella\n",
"25 Charlotte\n",
"26 Amelia\n",
"27 Mia\n",
"28 Harper\n",
"29 Evelyn\n",
" ... \n",
"50 Liam\n",
"51 Noah\n",
"52 William\n",
"53 James\n",
"54 Oliver\n",
"55 Benjamin\n",
"56 Elijah\n",
"57 Lucas\n",
"58 Mason\n",
"59 Logan\n",
"60 Emma\n",
"61 Olivia\n",
"62 Ava\n",
"63 Isabella\n",
"64 Sophia\n",
"65 Mia\n",
"66 Charlotte\n",
"67 Amelia\n",
"68 Evelyn\n",
"69 Abigail\n",
"70 Liam\n",
"71 Noah\n",
"72 William\n",
"73 James\n",
"74 Logan\n",
"75 Benjamin\n",
"76 Mason\n",
"77 Elijah\n",
"78 Jacob\n",
"79 Oliver\n",
"Name: Name, Length: 80, dtype: object"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['Name'] # Gets all the values from specified column 'Name'"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Name object\n",
"Sex object\n",
"Frequency int64\n",
"Year int64\n",
"dtype: object"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.dtypes # Shows the data types"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"25"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['Name'].nunique() # Number of unique names in the data"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"11"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[df['Sex'] == 'F']['Name'].nunique() # Number of unique female names"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"14"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"### YOUR TASK HERE\n",
"# Find the number of unique male names\n",
"\n",
"df[df['Sex'] == 'M']['Name'].nunique()\n"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
Frequency
Name
Liam78962
Noah74168
William55751
Oliver54757
James53308
\n",
"
"
],
"text/plain": [
" Frequency\n",
"Name \n",
"Liam 78962\n",
"Noah 74168\n",
"William 55751\n",
"Oliver 54757\n",
"James 53308"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# The 5 most popular male names from 2017-2020\n",
"df[df['Sex'] == 'M'][['Name', 'Frequency']].groupby('Name').sum().sort_values('Frequency', ascending=False).head()"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
Frequency
Name
Olivia72798
Emma71343
Ava58531
Sophia55611
Isabella55148
\n",
"
"
],
"text/plain": [
" Frequency\n",
"Name \n",
"Olivia 72798\n",
"Emma 71343\n",
"Ava 58531\n",
"Sophia 55611\n",
"Isabella 55148"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"### YOUR TASK HERE\n",
"# Find the 5 most popular female names. \n",
"\n",
"df[df['Sex'] == 'F'][['Name', 'Frequency']].groupby('Name').sum().sort_values('Frequency', ascending=False).head()\n"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
""
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png":...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions ยป

Submit New Assignment

Copy and Paste Your Assignment Here