diff --git a/03_Grouping/Alcohol_Consumption/Exercise.ipynb b/03_Grouping/Alcohol_Consumption/Exercise.ipynb
index d49a518b5..d0c6a72c7 100644
--- a/03_Grouping/Alcohol_Consumption/Exercise.ipynb
+++ b/03_Grouping/Alcohol_Consumption/Exercise.ipynb
@@ -123,23 +123,23 @@
],
"metadata": {
"kernelspec": {
- "display_name": "Python 2",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
- "name": "python2"
+ "name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
- "version": 2
+ "version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
- "pygments_lexer": "ipython2",
- "version": "2.7.16"
+ "pygments_lexer": "ipython3",
+ "version": "3.12.6"
}
},
"nbformat": 4,
- "nbformat_minor": 0
+ "nbformat_minor": 4
}
diff --git a/03_Grouping/Alcohol_Consumption/Exercise_with_solutions.ipynb b/03_Grouping/Alcohol_Consumption/Exercise_with_solutions.ipynb
index 841a5af59..d2391f475 100644
--- a/03_Grouping/Alcohol_Consumption/Exercise_with_solutions.ipynb
+++ b/03_Grouping/Alcohol_Consumption/Exercise_with_solutions.ipynb
@@ -25,7 +25,7 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@@ -43,7 +43,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "### Step 3. Assign it to a variable called drinks."
+ "### Step 3. Assign it to a variable called drinks.(Watch the values of Column continent NA (North America), and how Pandas interprets it!"
]
},
{
@@ -55,6 +55,19 @@
"data": {
"text/html": [
"
\n",
+ "\n",
"
\n",
" \n",
" \n",
@@ -139,7 +152,7 @@
}
],
"source": [
- "drinks = pd.read_csv('https://raw.githubusercontent.com/justmarkham/DAT8/master/data/drinks.csv')\n",
+ "drinks = pd.read_csv('https://raw.githubusercontent.com/justmarkham/DAT8/master/data/drinks.csv',keep_default_na=False)\n",
"drinks.head()"
]
},
@@ -152,7 +165,7 @@
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": 5,
"metadata": {},
"outputs": [
{
@@ -162,12 +175,13 @@
"AF 61.471698\n",
"AS 37.045455\n",
"EU 193.777778\n",
+ "NA 145.434783\n",
"OC 89.687500\n",
"SA 175.083333\n",
"Name: beer_servings, dtype: float64"
]
},
- "execution_count": 6,
+ "execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
@@ -185,57 +199,134 @@
},
{
"cell_type": "code",
- "execution_count": 9,
+ "execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
+ "text/html": [
+ "\n",
+ "\n",
+ "
\n",
+ " \n",
+ " \n",
+ " | \n",
+ " count | \n",
+ " mean | \n",
+ " std | \n",
+ " min | \n",
+ " 25% | \n",
+ " 50% | \n",
+ " 75% | \n",
+ " max | \n",
+ "
\n",
+ " \n",
+ " continent | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ " | \n",
+ "
\n",
+ " \n",
+ " \n",
+ " \n",
+ " AF | \n",
+ " 53.0 | \n",
+ " 16.264151 | \n",
+ " 38.846419 | \n",
+ " 0.0 | \n",
+ " 1.0 | \n",
+ " 2.0 | \n",
+ " 13.00 | \n",
+ " 233.0 | \n",
+ "
\n",
+ " \n",
+ " AS | \n",
+ " 44.0 | \n",
+ " 9.068182 | \n",
+ " 21.667034 | \n",
+ " 0.0 | \n",
+ " 0.0 | \n",
+ " 1.0 | \n",
+ " 8.00 | \n",
+ " 123.0 | \n",
+ "
\n",
+ " \n",
+ " EU | \n",
+ " 45.0 | \n",
+ " 142.222222 | \n",
+ " 97.421738 | \n",
+ " 0.0 | \n",
+ " 59.0 | \n",
+ " 128.0 | \n",
+ " 195.00 | \n",
+ " 370.0 | \n",
+ "
\n",
+ " \n",
+ " NA | \n",
+ " 23.0 | \n",
+ " 24.521739 | \n",
+ " 28.266378 | \n",
+ " 1.0 | \n",
+ " 5.0 | \n",
+ " 11.0 | \n",
+ " 34.00 | \n",
+ " 100.0 | \n",
+ "
\n",
+ " \n",
+ " OC | \n",
+ " 16.0 | \n",
+ " 35.625000 | \n",
+ " 64.555790 | \n",
+ " 0.0 | \n",
+ " 1.0 | \n",
+ " 8.5 | \n",
+ " 23.25 | \n",
+ " 212.0 | \n",
+ "
\n",
+ " \n",
+ " SA | \n",
+ " 12.0 | \n",
+ " 62.416667 | \n",
+ " 88.620189 | \n",
+ " 1.0 | \n",
+ " 3.0 | \n",
+ " 12.0 | \n",
+ " 98.50 | \n",
+ " 221.0 | \n",
+ "
\n",
+ " \n",
+ "
\n",
+ "
"
+ ],
"text/plain": [
- "continent \n",
- "AF count 53.000000\n",
- " mean 16.264151\n",
- " std 38.846419\n",
- " min 0.000000\n",
- " 25% 1.000000\n",
- " 50% 2.000000\n",
- " 75% 13.000000\n",
- " max 233.000000\n",
- "AS count 44.000000\n",
- " mean 9.068182\n",
- " std 21.667034\n",
- " min 0.000000\n",
- " 25% 0.000000\n",
- " 50% 1.000000\n",
- " 75% 8.000000\n",
- " max 123.000000\n",
- "EU count 45.000000\n",
- " mean 142.222222\n",
- " std 97.421738\n",
- " min 0.000000\n",
- " 25% 59.000000\n",
- " 50% 128.000000\n",
- " 75% 195.000000\n",
- " max 370.000000\n",
- "OC count 16.000000\n",
- " mean 35.625000\n",
- " std 64.555790\n",
- " min 0.000000\n",
- " 25% 1.000000\n",
- " 50% 8.500000\n",
- " 75% 23.250000\n",
- " max 212.000000\n",
- "SA count 12.000000\n",
- " mean 62.416667\n",
- " std 88.620189\n",
- " min 1.000000\n",
- " 25% 3.000000\n",
- " 50% 12.000000\n",
- " 75% 98.500000\n",
- " max 221.000000\n",
- "dtype: float64"
+ " count mean std min 25% 50% 75% max\n",
+ "continent \n",
+ "AF 53.0 16.264151 38.846419 0.0 1.0 2.0 13.00 233.0\n",
+ "AS 44.0 9.068182 21.667034 0.0 0.0 1.0 8.00 123.0\n",
+ "EU 45.0 142.222222 97.421738 0.0 59.0 128.0 195.00 370.0\n",
+ "NA 23.0 24.521739 28.266378 1.0 5.0 11.0 34.00 100.0\n",
+ "OC 16.0 35.625000 64.555790 0.0 1.0 8.5 23.25 212.0\n",
+ "SA 12.0 62.416667 88.620189 1.0 3.0 12.0 98.50 221.0"
]
},
- "execution_count": 9,
+ "execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
@@ -253,13 +344,26 @@
},
{
"cell_type": "code",
- "execution_count": 10,
+ "execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
+ "\n",
"
\n",
" \n",
" \n",
@@ -300,6 +404,13 @@
" 8.617778 | \n",
"
\n",
" \n",
+ " NA | \n",
+ " 145.434783 | \n",
+ " 165.739130 | \n",
+ " 24.521739 | \n",
+ " 5.995652 | \n",
+ "
\n",
+ " \n",
" OC | \n",
" 89.687500 | \n",
" 58.437500 | \n",
@@ -323,6 +434,7 @@
"AF 61.471698 16.339623 16.264151 \n",
"AS 37.045455 60.840909 9.068182 \n",
"EU 193.777778 132.555556 142.222222 \n",
+ "NA 145.434783 165.739130 24.521739 \n",
"OC 89.687500 58.437500 35.625000 \n",
"SA 175.083333 114.750000 62.416667 \n",
"\n",
@@ -331,17 +443,18 @@
"AF 3.007547 \n",
"AS 2.170455 \n",
"EU 8.617778 \n",
+ "NA 5.995652 \n",
"OC 3.381250 \n",
"SA 6.308333 "
]
},
- "execution_count": 10,
+ "execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "drinks.groupby('continent').mean()"
+ "drinks.groupby('continent').mean(numeric_only=True)"
]
},
{
@@ -353,13 +466,26 @@
},
{
"cell_type": "code",
- "execution_count": 14,
+ "execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
+ "\n",
"
\n",
" \n",
" \n",
@@ -400,6 +526,13 @@
" 10.00 | \n",
"
\n",
" \n",
+ " NA | \n",
+ " 143.0 | \n",
+ " 137.0 | \n",
+ " 11.0 | \n",
+ " 6.30 | \n",
+ "
\n",
+ " \n",
" OC | \n",
" 52.5 | \n",
" 37.0 | \n",
@@ -423,6 +556,7 @@
"AF 32.0 3.0 2.0 \n",
"AS 17.5 16.0 1.0 \n",
"EU 219.0 122.0 128.0 \n",
+ "NA 143.0 137.0 11.0 \n",
"OC 52.5 37.0 8.5 \n",
"SA 162.5 108.5 12.0 \n",
"\n",
@@ -431,36 +565,50 @@
"AF 2.30 \n",
"AS 1.20 \n",
"EU 10.00 \n",
+ "NA 6.30 \n",
"OC 1.75 \n",
"SA 6.85 "
]
},
- "execution_count": 14,
+ "execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
- "drinks.groupby('continent').median()"
+ "drinks.groupby('continent').median(numeric_only=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
- "### Step 8. Print the mean, min and max values for spirit consumption.\n",
+ "### Step 8. Print the mean, min and max values for spirit consumption for each Continent.\n",
"#### This time output a DataFrame"
]
},
{
"cell_type": "code",
- "execution_count": 15,
+ "execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
+ "\n",
"
\n",
" \n",
" \n",
@@ -496,6 +644,12 @@
" 373 | \n",
"
\n",
" \n",
+ " NA | \n",
+ " 165.739130 | \n",
+ " 68 | \n",
+ " 438 | \n",
+ "
\n",
+ " \n",
" OC | \n",
" 58.437500 | \n",
" 0 | \n",
@@ -517,11 +671,12 @@
"AF 16.339623 0 152\n",
"AS 60.840909 0 326\n",
"EU 132.555556 0 373\n",
+ "NA 165.739130 68 438\n",
"OC 58.437500 0 254\n",
"SA 114.750000 25 302"
]
},
- "execution_count": 15,
+ "execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
@@ -529,11 +684,18 @@
"source": [
"drinks.groupby('continent').spirit_servings.agg(['mean', 'min', 'max'])"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
],
"metadata": {
"kernelspec": {
- "display_name": "Python 3",
+ "display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -547,7 +709,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.3"
+ "version": "3.12.6"
},
"toc": {
"base_numbering": 1,
@@ -564,5 +726,5 @@
}
},
"nbformat": 4,
- "nbformat_minor": 1
+ "nbformat_minor": 4
}
diff --git a/03_Grouping/Alcohol_Consumption/Solutions.ipynb b/03_Grouping/Alcohol_Consumption/Solutions.ipynb
index 3783e0b23..61da21c51 100644
--- a/03_Grouping/Alcohol_Consumption/Solutions.ipynb
+++ b/03_Grouping/Alcohol_Consumption/Solutions.ipynb
@@ -39,7 +39,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "### Step 3. Assign it to a variable called drinks."
+ "### Step 3. Assign it to a variable called drinks (Watch the values of the Column 'Continent' NA (North America), and how Pandas interprets it!"
]
},
{
@@ -433,7 +433,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "### Step 8. Print the mean, min and max values for spirit consumption.\n",
+ "### Step 8. Print the mean, min and max values for spirit consumption by Continent.\n",
"#### This time output a DataFrame"
]
},