Skip to content

Commit 6f12d1f

Browse files
committedFeb 7, 2016
full course added
1 parent b24e8f6 commit 6f12d1f

32 files changed

+1714
-570
lines changed
 

‎LABS/.ipynb_checkpoints/LAB 1. Hello Python!-checkpoint.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,21 @@
9696
],
9797
"metadata": {
9898
"kernelspec": {
99-
"display_name": "Python 2",
99+
"display_name": "Python 3",
100100
"language": "python",
101-
"name": "python2"
101+
"name": "python3"
102102
},
103103
"language_info": {
104104
"codemirror_mode": {
105105
"name": "ipython",
106-
"version": 2
106+
"version": 3
107107
},
108108
"file_extension": ".py",
109109
"mimetype": "text/x-python",
110110
"name": "python",
111111
"nbconvert_exporter": "python",
112-
"pygments_lexer": "ipython2",
113-
"version": "2.7.11"
112+
"pygments_lexer": "ipython3",
113+
"version": "3.5.1"
114114
}
115115
},
116116
"nbformat": 4,

‎LABS/.ipynb_checkpoints/LAB 10. 2D Numpy Arraya-checkpoint.ipynb

Lines changed: 0 additions & 142 deletions
This file was deleted.

‎LABS/.ipynb_checkpoints/LAB 11. Basic Statistics with Numpy-checkpoint.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,21 @@
8686
],
8787
"metadata": {
8888
"kernelspec": {
89-
"display_name": "Python 2",
89+
"display_name": "Python 3",
9090
"language": "python",
91-
"name": "python2"
91+
"name": "python3"
9292
},
9393
"language_info": {
9494
"codemirror_mode": {
9595
"name": "ipython",
96-
"version": 2
96+
"version": 3
9797
},
9898
"file_extension": ".py",
9999
"mimetype": "text/x-python",
100100
"name": "python",
101101
"nbconvert_exporter": "python",
102-
"pygments_lexer": "ipython2",
103-
"version": "2.7.11"
102+
"pygments_lexer": "ipython3",
103+
"version": "3.5.1"
104104
}
105105
},
106106
"nbformat": 4,
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": [
11+
"# Print the last item from year and pop\n",
12+
"print(year[-1])\n",
13+
"print(pop[-1])\n",
14+
"\n",
15+
"\n",
16+
"# Import matplotlib.pyplot as plt\n",
17+
"import matplotlib.pyplot as plt\n",
18+
"\n",
19+
"# Make a line plot: year on the x-axis, pop on the y-axis\n",
20+
"plt.plot(year, pop)\n",
21+
"plt.show()"
22+
]
23+
},
24+
{
25+
"cell_type": "markdown",
26+
"metadata": {},
27+
"source": [
28+
"1. Have another look at the plot you created in the previous exercise; it's shown on the right. What is the first year in which there will be more than ten billion human beings on this planet?\n",
29+
" - 2062"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"metadata": {
36+
"collapsed": true
37+
},
38+
"outputs": [],
39+
"source": [
40+
"# Print the last item of gdp_cap and life_exp\n",
41+
"print(gdp_cap[-1])\n",
42+
"print(life_exp[-1])\n",
43+
"\n",
44+
"\n",
45+
"# Make a line plot, gdp_cap on the x-axis, life_exp on the y-axis\n",
46+
"plt.plot(gdp_cap, life_exp)\n",
47+
"\n",
48+
"# Display the plot\n",
49+
"plt.show()"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": null,
55+
"metadata": {
56+
"collapsed": true
57+
},
58+
"outputs": [],
59+
"source": [
60+
"# Change the line plot below to a scatter plot\n",
61+
"plt.scatter(gdp_cap, life_exp)\n",
62+
"\n",
63+
"# Put the x-axis on a logarithmic scale\n",
64+
"plt.xscale(\"log\")\n",
65+
"\n",
66+
"# Show plot\n",
67+
"plt.show()"
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": null,
73+
"metadata": {
74+
"collapsed": true
75+
},
76+
"outputs": [],
77+
"source": [
78+
"# Import package\n",
79+
"import matplotlib.pyplot as plt\n",
80+
"\n",
81+
"# Build Scatter plot\n",
82+
"plt.scatter(pop, life_exp)\n",
83+
"\n",
84+
"# Show plot\n",
85+
"plt.show()"
86+
]
87+
}
88+
],
89+
"metadata": {
90+
"kernelspec": {
91+
"display_name": "Python 3",
92+
"language": "python",
93+
"name": "python3"
94+
},
95+
"language_info": {
96+
"codemirror_mode": {
97+
"name": "ipython",
98+
"version": 3
99+
},
100+
"file_extension": ".py",
101+
"mimetype": "text/x-python",
102+
"name": "python",
103+
"nbconvert_exporter": "python",
104+
"pygments_lexer": "ipython3",
105+
"version": "3.5.1"
106+
}
107+
},
108+
"nbformat": 4,
109+
"nbformat_minor": 0
110+
}

‎LABS/.ipynb_checkpoints/LAB 12. Basic Statistics with Numpy-checkpoint.ipynb

Lines changed: 0 additions & 108 deletions
This file was deleted.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": [
11+
"# Create histogram of life_exp data\n",
12+
"plt.hist(life_exp)\n",
13+
"\n",
14+
"# Display histogram\n",
15+
"plt.show()"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": null,
21+
"metadata": {
22+
"collapsed": true
23+
},
24+
"outputs": [],
25+
"source": [
26+
"# Build histogram with 5 bins\n",
27+
"plt.hist(life_exp, bins = 5)\n",
28+
"\n",
29+
"# Show and clean up plot\n",
30+
"plt.show()\n",
31+
"plt.clf()\n",
32+
"\n",
33+
"# Build histogram with 20 bins\n",
34+
"plt.hist(life_exp, bins = 20)\n",
35+
"\n",
36+
"# Show and clean up again\n",
37+
"plt.show()\n",
38+
"plt.clf()"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": null,
44+
"metadata": {
45+
"collapsed": true
46+
},
47+
"outputs": [],
48+
"source": [
49+
"# Histogram of life_exp, 15 bins\n",
50+
"plt.hist(life_exp, bins = 15)\n",
51+
"\n",
52+
"# Show and clear plot\n",
53+
"plt.show()\n",
54+
"plt.clf()\n",
55+
"\n",
56+
"# Histogram of life_exp1950, 15 bins\n",
57+
"plt.hist(life_exp1950, bins = 15)\n",
58+
"\n",
59+
"# Show and clear plot again\n",
60+
"plt.show()\n",
61+
"plt.clf()"
62+
]
63+
},
64+
{
65+
"cell_type": "markdown",
66+
"metadata": {},
67+
"source": [
68+
"# Choose the right plot (1)\n",
69+
"1. You're a professor teaching Data Science with Python, and you want to visually assess if the grades on your exam follow a normal distribution. Which plot do you use?\n",
70+
" - Histogram"
71+
]
72+
},
73+
{
74+
"cell_type": "markdown",
75+
"metadata": {},
76+
"source": [
77+
"# Choose the right plot (2)\n",
78+
"1. You're a professor in Data Analytics with Python, and you want to visually assess if longer answers on exam questions lead to higher grades. Which plot do you use?\n",
79+
" - Scatter plot"
80+
]
81+
}
82+
],
83+
"metadata": {
84+
"kernelspec": {
85+
"display_name": "Python 3",
86+
"language": "python",
87+
"name": "python3"
88+
},
89+
"language_info": {
90+
"codemirror_mode": {
91+
"name": "ipython",
92+
"version": 3
93+
},
94+
"file_extension": ".py",
95+
"mimetype": "text/x-python",
96+
"name": "python",
97+
"nbconvert_exporter": "python",
98+
"pygments_lexer": "ipython3",
99+
"version": "3.5.1"
100+
}
101+
},
102+
"nbformat": 4,
103+
"nbformat_minor": 0
104+
}
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": [
11+
"# Basic scatter plot, log scale\n",
12+
"plt.scatter(gdp_cap, life_exp)\n",
13+
"plt.xscale('log') \n",
14+
"\n",
15+
"# Strings\n",
16+
"xlab = 'GDP per Capita [in USD]'\n",
17+
"ylab = 'Life Expectancy [in years]'\n",
18+
"title = 'World Development in 2007'\n",
19+
"\n",
20+
"# Add axis labels\n",
21+
"plt.xlabel(xlab)\n",
22+
"plt.ylabel(ylab)\n",
23+
"\n",
24+
"\n",
25+
"# Add title\n",
26+
"plt.title(title)\n",
27+
"\n",
28+
"# After customizing, display the plot\n",
29+
"plt.show()"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"metadata": {
36+
"collapsed": true
37+
},
38+
"outputs": [],
39+
"source": [
40+
"# Scatter plot\n",
41+
"plt.scatter(gdp_cap, life_exp)\n",
42+
"\n",
43+
"# Previous customizations\n",
44+
"plt.xscale('log') \n",
45+
"plt.xlabel('GDP per Capita [in USD]')\n",
46+
"plt.ylabel('Life Expectancy [in years]')\n",
47+
"plt.title('World Development in 2007')\n",
48+
"\n",
49+
"# Definition of tick_val and tick_lab\n",
50+
"tick_val = [1000,10000,100000]\n",
51+
"tick_lab = ['1k','10k','100k']\n",
52+
"\n",
53+
"# Adapt the ticks on the x-axis\n",
54+
"plt.xticks(tick_val, tick_lab)\n",
55+
"\n",
56+
"\n",
57+
"# After customizing, display the plot\n",
58+
"plt.show()"
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": null,
64+
"metadata": {
65+
"collapsed": true
66+
},
67+
"outputs": [],
68+
"source": [
69+
"# Import numpy as np\n",
70+
"import numpy as np\n",
71+
"\n",
72+
"# Store pop as a numpy array: np_pop\n",
73+
"np_pop = np.array(pop)\n",
74+
"\n",
75+
"# Double np_pop\n",
76+
"np_pop *= 2\n",
77+
"\n",
78+
"# Update: set s argument to np_pop\n",
79+
"plt.scatter(gdp_cap, life_exp, s = np_pop)\n",
80+
"\n",
81+
"# Previous customizations\n",
82+
"plt.xscale('log') \n",
83+
"plt.xlabel('GDP per Capita [in USD]')\n",
84+
"plt.ylabel('Life Expectancy [in years]')\n",
85+
"plt.title('World Development in 2007')\n",
86+
"plt.xticks([1000, 10000, 100000],['1k', '10k', '100k'])\n",
87+
"\n",
88+
"# Display the plot\n",
89+
"plt.show()"
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": null,
95+
"metadata": {
96+
"collapsed": true
97+
},
98+
"outputs": [],
99+
"source": [
100+
"# Specify c and alpha inside plt.scatter()\n",
101+
"plt.scatter(x = gdp_cap, y = life_exp, s = np.array(pop) * 2, c = col, alpha = 0.8)\n",
102+
"\n",
103+
"# Previous customizations\n",
104+
"plt.xscale('log') \n",
105+
"plt.xlabel('GDP per Capita [in USD]')\n",
106+
"plt.ylabel('Life Expectancy [in years]')\n",
107+
"plt.title('World Development in 2007')\n",
108+
"plt.xticks([1000,10000,100000], ['1k','10k','100k'])\n",
109+
"\n",
110+
"# Show the plot\n",
111+
"plt.show()"
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": null,
117+
"metadata": {
118+
"collapsed": true
119+
},
120+
"outputs": [],
121+
"source": [
122+
"# Scatter plot\n",
123+
"plt.scatter(x = gdp_cap, y = life_exp, s = np.array(pop) * 2, c = col, alpha = 0.8)\n",
124+
"\n",
125+
"# Previous customizations\n",
126+
"plt.xscale('log') \n",
127+
"plt.xlabel('GDP per Capita [in USD]')\n",
128+
"plt.ylabel('Life Expectancy [in years]')\n",
129+
"plt.title('World Development in 2007')\n",
130+
"plt.xticks([1000,10000,100000], ['1k','10k','100k'])\n",
131+
"\n",
132+
"# Additional customizations\n",
133+
"plt.text(1550, 71, 'India')\n",
134+
"plt.text(5700, 80, 'China')\n",
135+
"\n",
136+
"# Add grid() call\n",
137+
"plt.grid(True)\n",
138+
"\n",
139+
"# Show the plot\n",
140+
"plt.show()"
141+
]
142+
},
143+
{
144+
"cell_type": "markdown",
145+
"metadata": {},
146+
"source": [
147+
"# Interpretation\n",
148+
"1. If you have a look at your colorful plot, it's clear that people live longer in countries with a higher GDP per capita. No high income countries have really short life expectancy, and no low income countries have very long life expectancy. Still, there is a huge difference in life expectancy between countries on the same income level. Most people live in middle income countries where difference in lifespan is huge between countries; depending on how income is distributed and how it is used. What can you say about the plot?\n",
149+
" - The countries in blue, corresponding to Africa, have both low life expectancy and a low GDP per capita."
150+
]
151+
}
152+
],
153+
"metadata": {
154+
"kernelspec": {
155+
"display_name": "Python 3",
156+
"language": "python",
157+
"name": "python3"
158+
},
159+
"language_info": {
160+
"codemirror_mode": {
161+
"name": "ipython",
162+
"version": 3
163+
},
164+
"file_extension": ".py",
165+
"mimetype": "text/x-python",
166+
"name": "python",
167+
"nbconvert_exporter": "python",
168+
"pygments_lexer": "ipython3",
169+
"version": "3.5.1"
170+
}
171+
},
172+
"nbformat": 4,
173+
"nbformat_minor": 0
174+
}
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {
7+
"collapsed": false
8+
},
9+
"outputs": [
10+
{
11+
"name": "stdout",
12+
"output_type": "stream",
13+
"text": [
14+
"False\n",
15+
"True\n",
16+
"False\n",
17+
"True\n"
18+
]
19+
}
20+
],
21+
"source": [
22+
"# Comparison of booleans\n",
23+
"print(True == False)\n",
24+
"\n",
25+
"# Comparison of integers\n",
26+
"print(-5*15!=75)\n",
27+
"\n",
28+
"# Comparison of strings\n",
29+
"print(\"pyscript\" == \"PyScript\")\n",
30+
"\n",
31+
"# Compare a boolean with an integer\n",
32+
"print(True == 1)"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": 2,
38+
"metadata": {
39+
"collapsed": false
40+
},
41+
"outputs": [
42+
{
43+
"name": "stdout",
44+
"output_type": "stream",
45+
"text": [
46+
"False\n",
47+
"True\n",
48+
"True\n"
49+
]
50+
}
51+
],
52+
"source": [
53+
"# Comparison of integers\n",
54+
"x = -3 * 6\n",
55+
"print(x >= -10)\n",
56+
"\n",
57+
"# Comparison of strings\n",
58+
"y = \"test\"\n",
59+
"print(\"test\" <= y)\n",
60+
"\n",
61+
"# Comparison of booleans\n",
62+
"print(True > False)"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": 3,
68+
"metadata": {
69+
"collapsed": false
70+
},
71+
"outputs": [
72+
{
73+
"name": "stdout",
74+
"output_type": "stream",
75+
"text": [
76+
"False\n",
77+
"True\n",
78+
"True\n"
79+
]
80+
}
81+
],
82+
"source": [
83+
"# Define variables\n",
84+
"my_kitchen = 18.0\n",
85+
"your_kitchen = 14.0\n",
86+
"\n",
87+
"# my_kitchen bigger than 10 and smaller than 18?\n",
88+
"print(my_kitchen > 10 and my_kitchen < 18)\n",
89+
"\n",
90+
"# my_kitchen smaller than 14 or bigger than 17?\n",
91+
"print(my_kitchen < 14 or my_kitchen > 17)\n",
92+
"\n",
93+
"# Double my_kitchen smaller than triple your_kitchen?\n",
94+
"print(my_kitchen * 2 < your_kitchen*3)"
95+
]
96+
},
97+
{
98+
"cell_type": "markdown",
99+
"metadata": {},
100+
"source": [
101+
"# and, or, not (2)\n",
102+
"1. To see if you completely understood the boolean operators, have a look at the following piece of Python code: x = 8: y = 9; not(not(x < 3) and not(y > 14 or y > 10)). What will the result be if you exectue these three commands in the IPython Shell? NB: Notice that not has a higher priority than and and or, it is executed first.\n",
103+
" - False"
104+
]
105+
},
106+
{
107+
"cell_type": "markdown",
108+
"metadata": {},
109+
"source": [
110+
"# Warmup\n",
111+
"1- To experiment with if and else a bit, have a look at this code sample: area = 10.0; if(area < 9) : print(\"small\") elif(area < 12) : print(\"medium\") else : print(\"large\"). What will the output be if you run this piece of code in the IPython Shell?\n",
112+
" - medium"
113+
]
114+
},
115+
{
116+
"cell_type": "code",
117+
"execution_count": null,
118+
"metadata": {
119+
"collapsed": true
120+
},
121+
"outputs": [],
122+
"source": [
123+
"# Define variables\n",
124+
"room = \"kit\"\n",
125+
"area = 14.0\n",
126+
"\n",
127+
"# if statement for room\n",
128+
"if room == \"kit\" :\n",
129+
" print(\"looking around in the kitchen.\")\n",
130+
"\n",
131+
"# if statement for area\n",
132+
"if area > 15:\n",
133+
" print(\"big place!\")"
134+
]
135+
},
136+
{
137+
"cell_type": "code",
138+
"execution_count": null,
139+
"metadata": {
140+
"collapsed": true
141+
},
142+
"outputs": [],
143+
"source": [
144+
"# Define variables\n",
145+
"room = \"kit\"\n",
146+
"area = 14.0\n",
147+
"\n",
148+
"# if-else construct for room\n",
149+
"if room == \"kit\" :\n",
150+
" print(\"looking around in the kitchen.\")\n",
151+
"else :\n",
152+
" print(\"looking around elsewhere.\")\n",
153+
"\n",
154+
"# if-else construct for area\n",
155+
"if area > 15 :\n",
156+
" print(\"big place!\")\n",
157+
"else:\n",
158+
" print(\"pretty small.\")"
159+
]
160+
},
161+
{
162+
"cell_type": "code",
163+
"execution_count": null,
164+
"metadata": {
165+
"collapsed": true
166+
},
167+
"outputs": [],
168+
"source": [
169+
"# Define variables\n",
170+
"room = \"bed\"\n",
171+
"area = 14.0\n",
172+
"\n",
173+
"# if-elif-else construct for room\n",
174+
"if room == \"kit\" :\n",
175+
" print(\"looking around in the kitchen.\")\n",
176+
"elif room == \"bed\":\n",
177+
" print(\"looking around in the bedroom.\")\n",
178+
"else :\n",
179+
" print(\"looking around elsewhere.\")\n",
180+
"\n",
181+
"# if-elif-else construct for area\n",
182+
"if area > 15 :\n",
183+
" print(\"big place!\")\n",
184+
"elif area > 10:\n",
185+
" print(\"medium size, nice!\")\n",
186+
"else :\n",
187+
" print(\"pretty small.\")"
188+
]
189+
}
190+
],
191+
"metadata": {
192+
"kernelspec": {
193+
"display_name": "Python 3",
194+
"language": "python",
195+
"name": "python3"
196+
},
197+
"language_info": {
198+
"codemirror_mode": {
199+
"name": "ipython",
200+
"version": 3
201+
},
202+
"file_extension": ".py",
203+
"mimetype": "text/x-python",
204+
"name": "python",
205+
"nbconvert_exporter": "python",
206+
"pygments_lexer": "ipython3",
207+
"version": "3.5.1"
208+
}
209+
},
210+
"nbformat": 4,
211+
"nbformat_minor": 0
212+
}
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": [
11+
"# Import pandas as pd\n",
12+
"import pandas as pd\n",
13+
"\n",
14+
"# Import the cars.csv data: cars\n",
15+
"cars = pd.read_csv(\"cars.csv\")\n",
16+
"\n",
17+
"# Print out cars\n",
18+
"print(cars)"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"metadata": {
25+
"collapsed": true
26+
},
27+
"outputs": [],
28+
"source": [
29+
"# Import pandas as pd\n",
30+
"import pandas as pd\n",
31+
"\n",
32+
"# Fix import by including index_col\n",
33+
"cars = pd.read_csv('cars.csv', index_col = 0)\n",
34+
"\n",
35+
"# Print out cars\n",
36+
"print(cars)"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {
43+
"collapsed": true
44+
},
45+
"outputs": [],
46+
"source": [
47+
"# Import cars data\n",
48+
"import pandas as pd\n",
49+
"cars = pd.read_csv('cars.csv', index_col = 0)\n",
50+
"\n",
51+
"# Print out country column as Pandas Series\n",
52+
"print(cars.country)\n",
53+
"\n",
54+
"# Print out country column as Pandas DataFrame\n",
55+
"print(cars[[\"country\"]])"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": null,
61+
"metadata": {
62+
"collapsed": true
63+
},
64+
"outputs": [],
65+
"source": [
66+
"# Import cars data\n",
67+
"import pandas as pd\n",
68+
"cars = pd.read_csv('cars.csv', index_col = 0)\n",
69+
"\n",
70+
"# Print out observation for Japan\n",
71+
"print(cars.loc[\"JAP\"])\n",
72+
"\n",
73+
"# Print out observations for Australia and Egypt\n",
74+
"print(cars.loc[[\"AUS\", \"EG\"]])"
75+
]
76+
},
77+
{
78+
"cell_type": "code",
79+
"execution_count": null,
80+
"metadata": {
81+
"collapsed": true
82+
},
83+
"outputs": [],
84+
"source": [
85+
"# Import cars data\n",
86+
"import pandas as pd\n",
87+
"cars = pd.read_csv('cars.csv', index_col = 0)\n",
88+
"\n",
89+
"# Print out drive_right value of Morocco\n",
90+
"print(cars.loc[\"MOR\", \"drives_right\"])\n",
91+
"\n",
92+
"# Print sub-DataFrame\n",
93+
"print(cars.loc[[\"RU\", \"MOR\"], [\"country\", \"drives_right\"]])"
94+
]
95+
}
96+
],
97+
"metadata": {
98+
"kernelspec": {
99+
"display_name": "Python 3",
100+
"language": "python",
101+
"name": "python3"
102+
},
103+
"language_info": {
104+
"codemirror_mode": {
105+
"name": "ipython",
106+
"version": 3
107+
},
108+
"file_extension": ".py",
109+
"mimetype": "text/x-python",
110+
"name": "python",
111+
"nbconvert_exporter": "python",
112+
"pygments_lexer": "ipython3",
113+
"version": "3.5.1"
114+
}
115+
},
116+
"nbformat": 4,
117+
"nbformat_minor": 0
118+
}

‎LABS/.ipynb_checkpoints/LAB 2. Variables and Types-checkpoint.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,21 @@
151151
],
152152
"metadata": {
153153
"kernelspec": {
154-
"display_name": "Python 2",
154+
"display_name": "Python 3",
155155
"language": "python",
156-
"name": "python2"
156+
"name": "python3"
157157
},
158158
"language_info": {
159159
"codemirror_mode": {
160160
"name": "ipython",
161-
"version": 2
161+
"version": 3
162162
},
163163
"file_extension": ".py",
164164
"mimetype": "text/x-python",
165165
"name": "python",
166166
"nbconvert_exporter": "python",
167-
"pygments_lexer": "ipython2",
168-
"version": "2.7.11"
167+
"pygments_lexer": "ipython3",
168+
"version": "3.5.1"
169169
}
170170
},
171171
"nbformat": 4,

‎LABS/.ipynb_checkpoints/LAB 3. Python Lists-checkpoint.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,21 @@
105105
],
106106
"metadata": {
107107
"kernelspec": {
108-
"display_name": "Python 2",
108+
"display_name": "Python 3",
109109
"language": "python",
110-
"name": "python2"
110+
"name": "python3"
111111
},
112112
"language_info": {
113113
"codemirror_mode": {
114114
"name": "ipython",
115-
"version": 2
115+
"version": 3
116116
},
117117
"file_extension": ".py",
118118
"mimetype": "text/x-python",
119119
"name": "python",
120120
"nbconvert_exporter": "python",
121-
"pygments_lexer": "ipython2",
122-
"version": "2.7.11"
121+
"pygments_lexer": "ipython3",
122+
"version": "3.5.1"
123123
}
124124
},
125125
"nbformat": 4,

‎LABS/.ipynb_checkpoints/LAB 4. Subsetting Lists-checkpoint.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,21 @@
117117
],
118118
"metadata": {
119119
"kernelspec": {
120-
"display_name": "Python 2",
120+
"display_name": "Python 3",
121121
"language": "python",
122-
"name": "python2"
122+
"name": "python3"
123123
},
124124
"language_info": {
125125
"codemirror_mode": {
126126
"name": "ipython",
127-
"version": 2
127+
"version": 3
128128
},
129129
"file_extension": ".py",
130130
"mimetype": "text/x-python",
131131
"name": "python",
132132
"nbconvert_exporter": "python",
133-
"pygments_lexer": "ipython2",
134-
"version": "2.7.11"
133+
"pygments_lexer": "ipython3",
134+
"version": "3.5.1"
135135
}
136136
},
137137
"nbformat": 4,

‎LABS/.ipynb_checkpoints/LAB 5. Manipulating Lists-checkpoint.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,21 @@
7777
],
7878
"metadata": {
7979
"kernelspec": {
80-
"display_name": "Python 2",
80+
"display_name": "Python 3",
8181
"language": "python",
82-
"name": "python2"
82+
"name": "python3"
8383
},
8484
"language_info": {
8585
"codemirror_mode": {
8686
"name": "ipython",
87-
"version": 2
87+
"version": 3
8888
},
8989
"file_extension": ".py",
9090
"mimetype": "text/x-python",
9191
"name": "python",
9292
"nbconvert_exporter": "python",
93-
"pygments_lexer": "ipython2",
94-
"version": "2.7.11"
93+
"pygments_lexer": "ipython3",
94+
"version": "3.5.1"
9595
}
9696
},
9797
"nbformat": 4,

‎LABS/.ipynb_checkpoints/LAB 9. Numpy-checkpoint.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,21 @@
144144
],
145145
"metadata": {
146146
"kernelspec": {
147-
"display_name": "Python 2",
147+
"display_name": "Python 3",
148148
"language": "python",
149-
"name": "python2"
149+
"name": "python3"
150150
},
151151
"language_info": {
152152
"codemirror_mode": {
153153
"name": "ipython",
154-
"version": 2
154+
"version": 3
155155
},
156156
"file_extension": ".py",
157157
"mimetype": "text/x-python",
158158
"name": "python",
159159
"nbconvert_exporter": "python",
160-
"pygments_lexer": "ipython2",
161-
"version": "2.7.11"
160+
"pygments_lexer": "ipython3",
161+
"version": "3.5.1"
162162
}
163163
},
164164
"nbformat": 4,

‎LABS/LAB 1. Hello Python!.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,21 +96,21 @@
9696
],
9797
"metadata": {
9898
"kernelspec": {
99-
"display_name": "Python 2",
99+
"display_name": "Python 3",
100100
"language": "python",
101-
"name": "python2"
101+
"name": "python3"
102102
},
103103
"language_info": {
104104
"codemirror_mode": {
105105
"name": "ipython",
106-
"version": 2
106+
"version": 3
107107
},
108108
"file_extension": ".py",
109109
"mimetype": "text/x-python",
110110
"name": "python",
111111
"nbconvert_exporter": "python",
112-
"pygments_lexer": "ipython2",
113-
"version": "2.7.11"
112+
"pygments_lexer": "ipython3",
113+
"version": "3.5.1"
114114
}
115115
},
116116
"nbformat": 4,

‎LABS/LAB 10. 2D Numpy Arraya.ipynb

Lines changed: 0 additions & 142 deletions
This file was deleted.

‎LABS/LAB 11. Basic Statistics with Numpy.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,21 @@
8686
],
8787
"metadata": {
8888
"kernelspec": {
89-
"display_name": "Python 2",
89+
"display_name": "Python 3",
9090
"language": "python",
91-
"name": "python2"
91+
"name": "python3"
9292
},
9393
"language_info": {
9494
"codemirror_mode": {
9595
"name": "ipython",
96-
"version": 2
96+
"version": 3
9797
},
9898
"file_extension": ".py",
9999
"mimetype": "text/x-python",
100100
"name": "python",
101101
"nbconvert_exporter": "python",
102-
"pygments_lexer": "ipython2",
103-
"version": "2.7.11"
102+
"pygments_lexer": "ipython3",
103+
"version": "3.5.1"
104104
}
105105
},
106106
"nbformat": 4,
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": [
11+
"# Print the last item from year and pop\n",
12+
"print(year[-1])\n",
13+
"print(pop[-1])\n",
14+
"\n",
15+
"\n",
16+
"# Import matplotlib.pyplot as plt\n",
17+
"import matplotlib.pyplot as plt\n",
18+
"\n",
19+
"# Make a line plot: year on the x-axis, pop on the y-axis\n",
20+
"plt.plot(year, pop)\n",
21+
"plt.show()"
22+
]
23+
},
24+
{
25+
"cell_type": "markdown",
26+
"metadata": {},
27+
"source": [
28+
"1. Have another look at the plot you created in the previous exercise; it's shown on the right. What is the first year in which there will be more than ten billion human beings on this planet?\n",
29+
" - 2062"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"metadata": {
36+
"collapsed": true
37+
},
38+
"outputs": [],
39+
"source": [
40+
"# Print the last item of gdp_cap and life_exp\n",
41+
"print(gdp_cap[-1])\n",
42+
"print(life_exp[-1])\n",
43+
"\n",
44+
"\n",
45+
"# Make a line plot, gdp_cap on the x-axis, life_exp on the y-axis\n",
46+
"plt.plot(gdp_cap, life_exp)\n",
47+
"\n",
48+
"# Display the plot\n",
49+
"plt.show()"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": null,
55+
"metadata": {
56+
"collapsed": true
57+
},
58+
"outputs": [],
59+
"source": [
60+
"# Change the line plot below to a scatter plot\n",
61+
"plt.scatter(gdp_cap, life_exp)\n",
62+
"\n",
63+
"# Put the x-axis on a logarithmic scale\n",
64+
"plt.xscale(\"log\")\n",
65+
"\n",
66+
"# Show plot\n",
67+
"plt.show()"
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": null,
73+
"metadata": {
74+
"collapsed": true
75+
},
76+
"outputs": [],
77+
"source": [
78+
"# Import package\n",
79+
"import matplotlib.pyplot as plt\n",
80+
"\n",
81+
"# Build Scatter plot\n",
82+
"plt.scatter(pop, life_exp)\n",
83+
"\n",
84+
"# Show plot\n",
85+
"plt.show()"
86+
]
87+
}
88+
],
89+
"metadata": {
90+
"kernelspec": {
91+
"display_name": "Python 3",
92+
"language": "python",
93+
"name": "python3"
94+
},
95+
"language_info": {
96+
"codemirror_mode": {
97+
"name": "ipython",
98+
"version": 3
99+
},
100+
"file_extension": ".py",
101+
"mimetype": "text/x-python",
102+
"name": "python",
103+
"nbconvert_exporter": "python",
104+
"pygments_lexer": "ipython3",
105+
"version": "3.5.1"
106+
}
107+
},
108+
"nbformat": 4,
109+
"nbformat_minor": 0
110+
}

‎LABS/LAB 12. Basic Statistics with Numpy.ipynb

Lines changed: 0 additions & 108 deletions
This file was deleted.

‎LABS/LAB 13. Histograms.ipynb

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": [
11+
"# Create histogram of life_exp data\n",
12+
"plt.hist(life_exp)\n",
13+
"\n",
14+
"# Display histogram\n",
15+
"plt.show()"
16+
]
17+
},
18+
{
19+
"cell_type": "code",
20+
"execution_count": null,
21+
"metadata": {
22+
"collapsed": true
23+
},
24+
"outputs": [],
25+
"source": [
26+
"# Build histogram with 5 bins\n",
27+
"plt.hist(life_exp, bins = 5)\n",
28+
"\n",
29+
"# Show and clean up plot\n",
30+
"plt.show()\n",
31+
"plt.clf()\n",
32+
"\n",
33+
"# Build histogram with 20 bins\n",
34+
"plt.hist(life_exp, bins = 20)\n",
35+
"\n",
36+
"# Show and clean up again\n",
37+
"plt.show()\n",
38+
"plt.clf()"
39+
]
40+
},
41+
{
42+
"cell_type": "code",
43+
"execution_count": null,
44+
"metadata": {
45+
"collapsed": true
46+
},
47+
"outputs": [],
48+
"source": [
49+
"# Histogram of life_exp, 15 bins\n",
50+
"plt.hist(life_exp, bins = 15)\n",
51+
"\n",
52+
"# Show and clear plot\n",
53+
"plt.show()\n",
54+
"plt.clf()\n",
55+
"\n",
56+
"# Histogram of life_exp1950, 15 bins\n",
57+
"plt.hist(life_exp1950, bins = 15)\n",
58+
"\n",
59+
"# Show and clear plot again\n",
60+
"plt.show()\n",
61+
"plt.clf()"
62+
]
63+
},
64+
{
65+
"cell_type": "markdown",
66+
"metadata": {},
67+
"source": [
68+
"# Choose the right plot (1)\n",
69+
"1. You're a professor teaching Data Science with Python, and you want to visually assess if the grades on your exam follow a normal distribution. Which plot do you use?\n",
70+
" - Histogram"
71+
]
72+
},
73+
{
74+
"cell_type": "markdown",
75+
"metadata": {},
76+
"source": [
77+
"# Choose the right plot (2)\n",
78+
"1. You're a professor in Data Analytics with Python, and you want to visually assess if longer answers on exam questions lead to higher grades. Which plot do you use?\n",
79+
" - Scatter plot"
80+
]
81+
}
82+
],
83+
"metadata": {
84+
"kernelspec": {
85+
"display_name": "Python 3",
86+
"language": "python",
87+
"name": "python3"
88+
},
89+
"language_info": {
90+
"codemirror_mode": {
91+
"name": "ipython",
92+
"version": 3
93+
},
94+
"file_extension": ".py",
95+
"mimetype": "text/x-python",
96+
"name": "python",
97+
"nbconvert_exporter": "python",
98+
"pygments_lexer": "ipython3",
99+
"version": "3.5.1"
100+
}
101+
},
102+
"nbformat": 4,
103+
"nbformat_minor": 0
104+
}

‎LABS/LAB 14. Customization.ipynb

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": [
11+
"# Basic scatter plot, log scale\n",
12+
"plt.scatter(gdp_cap, life_exp)\n",
13+
"plt.xscale('log') \n",
14+
"\n",
15+
"# Strings\n",
16+
"xlab = 'GDP per Capita [in USD]'\n",
17+
"ylab = 'Life Expectancy [in years]'\n",
18+
"title = 'World Development in 2007'\n",
19+
"\n",
20+
"# Add axis labels\n",
21+
"plt.xlabel(xlab)\n",
22+
"plt.ylabel(ylab)\n",
23+
"\n",
24+
"\n",
25+
"# Add title\n",
26+
"plt.title(title)\n",
27+
"\n",
28+
"# After customizing, display the plot\n",
29+
"plt.show()"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"metadata": {
36+
"collapsed": true
37+
},
38+
"outputs": [],
39+
"source": [
40+
"# Scatter plot\n",
41+
"plt.scatter(gdp_cap, life_exp)\n",
42+
"\n",
43+
"# Previous customizations\n",
44+
"plt.xscale('log') \n",
45+
"plt.xlabel('GDP per Capita [in USD]')\n",
46+
"plt.ylabel('Life Expectancy [in years]')\n",
47+
"plt.title('World Development in 2007')\n",
48+
"\n",
49+
"# Definition of tick_val and tick_lab\n",
50+
"tick_val = [1000,10000,100000]\n",
51+
"tick_lab = ['1k','10k','100k']\n",
52+
"\n",
53+
"# Adapt the ticks on the x-axis\n",
54+
"plt.xticks(tick_val, tick_lab)\n",
55+
"\n",
56+
"\n",
57+
"# After customizing, display the plot\n",
58+
"plt.show()"
59+
]
60+
},
61+
{
62+
"cell_type": "code",
63+
"execution_count": null,
64+
"metadata": {
65+
"collapsed": true
66+
},
67+
"outputs": [],
68+
"source": [
69+
"# Import numpy as np\n",
70+
"import numpy as np\n",
71+
"\n",
72+
"# Store pop as a numpy array: np_pop\n",
73+
"np_pop = np.array(pop)\n",
74+
"\n",
75+
"# Double np_pop\n",
76+
"np_pop *= 2\n",
77+
"\n",
78+
"# Update: set s argument to np_pop\n",
79+
"plt.scatter(gdp_cap, life_exp, s = np_pop)\n",
80+
"\n",
81+
"# Previous customizations\n",
82+
"plt.xscale('log') \n",
83+
"plt.xlabel('GDP per Capita [in USD]')\n",
84+
"plt.ylabel('Life Expectancy [in years]')\n",
85+
"plt.title('World Development in 2007')\n",
86+
"plt.xticks([1000, 10000, 100000],['1k', '10k', '100k'])\n",
87+
"\n",
88+
"# Display the plot\n",
89+
"plt.show()"
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": null,
95+
"metadata": {
96+
"collapsed": true
97+
},
98+
"outputs": [],
99+
"source": [
100+
"# Specify c and alpha inside plt.scatter()\n",
101+
"plt.scatter(x = gdp_cap, y = life_exp, s = np.array(pop) * 2, c = col, alpha = 0.8)\n",
102+
"\n",
103+
"# Previous customizations\n",
104+
"plt.xscale('log') \n",
105+
"plt.xlabel('GDP per Capita [in USD]')\n",
106+
"plt.ylabel('Life Expectancy [in years]')\n",
107+
"plt.title('World Development in 2007')\n",
108+
"plt.xticks([1000,10000,100000], ['1k','10k','100k'])\n",
109+
"\n",
110+
"# Show the plot\n",
111+
"plt.show()"
112+
]
113+
},
114+
{
115+
"cell_type": "code",
116+
"execution_count": null,
117+
"metadata": {
118+
"collapsed": true
119+
},
120+
"outputs": [],
121+
"source": [
122+
"# Scatter plot\n",
123+
"plt.scatter(x = gdp_cap, y = life_exp, s = np.array(pop) * 2, c = col, alpha = 0.8)\n",
124+
"\n",
125+
"# Previous customizations\n",
126+
"plt.xscale('log') \n",
127+
"plt.xlabel('GDP per Capita [in USD]')\n",
128+
"plt.ylabel('Life Expectancy [in years]')\n",
129+
"plt.title('World Development in 2007')\n",
130+
"plt.xticks([1000,10000,100000], ['1k','10k','100k'])\n",
131+
"\n",
132+
"# Additional customizations\n",
133+
"plt.text(1550, 71, 'India')\n",
134+
"plt.text(5700, 80, 'China')\n",
135+
"\n",
136+
"# Add grid() call\n",
137+
"plt.grid(True)\n",
138+
"\n",
139+
"# Show the plot\n",
140+
"plt.show()"
141+
]
142+
},
143+
{
144+
"cell_type": "markdown",
145+
"metadata": {},
146+
"source": [
147+
"# Interpretation\n",
148+
"1. If you have a look at your colorful plot, it's clear that people live longer in countries with a higher GDP per capita. No high income countries have really short life expectancy, and no low income countries have very long life expectancy. Still, there is a huge difference in life expectancy between countries on the same income level. Most people live in middle income countries where difference in lifespan is huge between countries; depending on how income is distributed and how it is used. What can you say about the plot?\n",
149+
" - The countries in blue, corresponding to Africa, have both low life expectancy and a low GDP per capita."
150+
]
151+
}
152+
],
153+
"metadata": {
154+
"kernelspec": {
155+
"display_name": "Python 3",
156+
"language": "python",
157+
"name": "python3"
158+
},
159+
"language_info": {
160+
"codemirror_mode": {
161+
"name": "ipython",
162+
"version": 3
163+
},
164+
"file_extension": ".py",
165+
"mimetype": "text/x-python",
166+
"name": "python",
167+
"nbconvert_exporter": "python",
168+
"pygments_lexer": "ipython3",
169+
"version": "3.5.1"
170+
}
171+
},
172+
"nbformat": 4,
173+
"nbformat_minor": 0
174+
}
Lines changed: 212 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {
7+
"collapsed": false
8+
},
9+
"outputs": [
10+
{
11+
"name": "stdout",
12+
"output_type": "stream",
13+
"text": [
14+
"False\n",
15+
"True\n",
16+
"False\n",
17+
"True\n"
18+
]
19+
}
20+
],
21+
"source": [
22+
"# Comparison of booleans\n",
23+
"print(True == False)\n",
24+
"\n",
25+
"# Comparison of integers\n",
26+
"print(-5*15!=75)\n",
27+
"\n",
28+
"# Comparison of strings\n",
29+
"print(\"pyscript\" == \"PyScript\")\n",
30+
"\n",
31+
"# Compare a boolean with an integer\n",
32+
"print(True == 1)"
33+
]
34+
},
35+
{
36+
"cell_type": "code",
37+
"execution_count": 2,
38+
"metadata": {
39+
"collapsed": false
40+
},
41+
"outputs": [
42+
{
43+
"name": "stdout",
44+
"output_type": "stream",
45+
"text": [
46+
"False\n",
47+
"True\n",
48+
"True\n"
49+
]
50+
}
51+
],
52+
"source": [
53+
"# Comparison of integers\n",
54+
"x = -3 * 6\n",
55+
"print(x >= -10)\n",
56+
"\n",
57+
"# Comparison of strings\n",
58+
"y = \"test\"\n",
59+
"print(\"test\" <= y)\n",
60+
"\n",
61+
"# Comparison of booleans\n",
62+
"print(True > False)"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": 3,
68+
"metadata": {
69+
"collapsed": false
70+
},
71+
"outputs": [
72+
{
73+
"name": "stdout",
74+
"output_type": "stream",
75+
"text": [
76+
"False\n",
77+
"True\n",
78+
"True\n"
79+
]
80+
}
81+
],
82+
"source": [
83+
"# Define variables\n",
84+
"my_kitchen = 18.0\n",
85+
"your_kitchen = 14.0\n",
86+
"\n",
87+
"# my_kitchen bigger than 10 and smaller than 18?\n",
88+
"print(my_kitchen > 10 and my_kitchen < 18)\n",
89+
"\n",
90+
"# my_kitchen smaller than 14 or bigger than 17?\n",
91+
"print(my_kitchen < 14 or my_kitchen > 17)\n",
92+
"\n",
93+
"# Double my_kitchen smaller than triple your_kitchen?\n",
94+
"print(my_kitchen * 2 < your_kitchen*3)"
95+
]
96+
},
97+
{
98+
"cell_type": "markdown",
99+
"metadata": {},
100+
"source": [
101+
"# and, or, not (2)\n",
102+
"1. To see if you completely understood the boolean operators, have a look at the following piece of Python code: x = 8: y = 9; not(not(x < 3) and not(y > 14 or y > 10)). What will the result be if you exectue these three commands in the IPython Shell? NB: Notice that not has a higher priority than and and or, it is executed first.\n",
103+
" - False"
104+
]
105+
},
106+
{
107+
"cell_type": "markdown",
108+
"metadata": {},
109+
"source": [
110+
"# Warmup\n",
111+
"1- To experiment with if and else a bit, have a look at this code sample: area = 10.0; if(area < 9) : print(\"small\") elif(area < 12) : print(\"medium\") else : print(\"large\"). What will the output be if you run this piece of code in the IPython Shell?\n",
112+
" - medium"
113+
]
114+
},
115+
{
116+
"cell_type": "code",
117+
"execution_count": null,
118+
"metadata": {
119+
"collapsed": true
120+
},
121+
"outputs": [],
122+
"source": [
123+
"# Define variables\n",
124+
"room = \"kit\"\n",
125+
"area = 14.0\n",
126+
"\n",
127+
"# if statement for room\n",
128+
"if room == \"kit\" :\n",
129+
" print(\"looking around in the kitchen.\")\n",
130+
"\n",
131+
"# if statement for area\n",
132+
"if area > 15:\n",
133+
" print(\"big place!\")"
134+
]
135+
},
136+
{
137+
"cell_type": "code",
138+
"execution_count": null,
139+
"metadata": {
140+
"collapsed": true
141+
},
142+
"outputs": [],
143+
"source": [
144+
"# Define variables\n",
145+
"room = \"kit\"\n",
146+
"area = 14.0\n",
147+
"\n",
148+
"# if-else construct for room\n",
149+
"if room == \"kit\" :\n",
150+
" print(\"looking around in the kitchen.\")\n",
151+
"else :\n",
152+
" print(\"looking around elsewhere.\")\n",
153+
"\n",
154+
"# if-else construct for area\n",
155+
"if area > 15 :\n",
156+
" print(\"big place!\")\n",
157+
"else:\n",
158+
" print(\"pretty small.\")"
159+
]
160+
},
161+
{
162+
"cell_type": "code",
163+
"execution_count": null,
164+
"metadata": {
165+
"collapsed": true
166+
},
167+
"outputs": [],
168+
"source": [
169+
"# Define variables\n",
170+
"room = \"bed\"\n",
171+
"area = 14.0\n",
172+
"\n",
173+
"# if-elif-else construct for room\n",
174+
"if room == \"kit\" :\n",
175+
" print(\"looking around in the kitchen.\")\n",
176+
"elif room == \"bed\":\n",
177+
" print(\"looking around in the bedroom.\")\n",
178+
"else :\n",
179+
" print(\"looking around elsewhere.\")\n",
180+
"\n",
181+
"# if-elif-else construct for area\n",
182+
"if area > 15 :\n",
183+
" print(\"big place!\")\n",
184+
"elif area > 10:\n",
185+
" print(\"medium size, nice!\")\n",
186+
"else :\n",
187+
" print(\"pretty small.\")"
188+
]
189+
}
190+
],
191+
"metadata": {
192+
"kernelspec": {
193+
"display_name": "Python 3",
194+
"language": "python",
195+
"name": "python3"
196+
},
197+
"language_info": {
198+
"codemirror_mode": {
199+
"name": "ipython",
200+
"version": 3
201+
},
202+
"file_extension": ".py",
203+
"mimetype": "text/x-python",
204+
"name": "python",
205+
"nbconvert_exporter": "python",
206+
"pygments_lexer": "ipython3",
207+
"version": "3.5.1"
208+
}
209+
},
210+
"nbformat": 4,
211+
"nbformat_minor": 0
212+
}

‎LABS/LAB 16. Pandas.ipynb

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {
7+
"collapsed": true
8+
},
9+
"outputs": [],
10+
"source": [
11+
"# Import pandas as pd\n",
12+
"import pandas as pd\n",
13+
"\n",
14+
"# Import the cars.csv data: cars\n",
15+
"cars = pd.read_csv(\"cars.csv\")\n",
16+
"\n",
17+
"# Print out cars\n",
18+
"print(cars)"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"metadata": {
25+
"collapsed": true
26+
},
27+
"outputs": [],
28+
"source": [
29+
"# Import pandas as pd\n",
30+
"import pandas as pd\n",
31+
"\n",
32+
"# Fix import by including index_col\n",
33+
"cars = pd.read_csv('cars.csv', index_col = 0)\n",
34+
"\n",
35+
"# Print out cars\n",
36+
"print(cars)"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {
43+
"collapsed": true
44+
},
45+
"outputs": [],
46+
"source": [
47+
"# Import cars data\n",
48+
"import pandas as pd\n",
49+
"cars = pd.read_csv('cars.csv', index_col = 0)\n",
50+
"\n",
51+
"# Print out country column as Pandas Series\n",
52+
"print(cars.country)\n",
53+
"\n",
54+
"# Print out country column as Pandas DataFrame\n",
55+
"print(cars[[\"country\"]])"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": null,
61+
"metadata": {
62+
"collapsed": true
63+
},
64+
"outputs": [],
65+
"source": [
66+
"# Import cars data\n",
67+
"import pandas as pd\n",
68+
"cars = pd.read_csv('cars.csv', index_col = 0)\n",
69+
"\n",
70+
"# Print out observation for Japan\n",
71+
"print(cars.loc[\"JAP\"])\n",
72+
"\n",
73+
"# Print out observations for Australia and Egypt\n",
74+
"print(cars.loc[[\"AUS\", \"EG\"]])"
75+
]
76+
},
77+
{
78+
"cell_type": "code",
79+
"execution_count": null,
80+
"metadata": {
81+
"collapsed": true
82+
},
83+
"outputs": [],
84+
"source": [
85+
"# Import cars data\n",
86+
"import pandas as pd\n",
87+
"cars = pd.read_csv('cars.csv', index_col = 0)\n",
88+
"\n",
89+
"# Print out drive_right value of Morocco\n",
90+
"print(cars.loc[\"MOR\", \"drives_right\"])\n",
91+
"\n",
92+
"# Print sub-DataFrame\n",
93+
"print(cars.loc[[\"RU\", \"MOR\"], [\"country\", \"drives_right\"]])"
94+
]
95+
}
96+
],
97+
"metadata": {
98+
"kernelspec": {
99+
"display_name": "Python 3",
100+
"language": "python",
101+
"name": "python3"
102+
},
103+
"language_info": {
104+
"codemirror_mode": {
105+
"name": "ipython",
106+
"version": 3
107+
},
108+
"file_extension": ".py",
109+
"mimetype": "text/x-python",
110+
"name": "python",
111+
"nbconvert_exporter": "python",
112+
"pygments_lexer": "ipython3",
113+
"version": "3.5.1"
114+
}
115+
},
116+
"nbformat": 4,
117+
"nbformat_minor": 0
118+
}

‎LABS/LAB 2. Variables and Types.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,21 @@
151151
],
152152
"metadata": {
153153
"kernelspec": {
154-
"display_name": "Python 2",
154+
"display_name": "Python 3",
155155
"language": "python",
156-
"name": "python2"
156+
"name": "python3"
157157
},
158158
"language_info": {
159159
"codemirror_mode": {
160160
"name": "ipython",
161-
"version": 2
161+
"version": 3
162162
},
163163
"file_extension": ".py",
164164
"mimetype": "text/x-python",
165165
"name": "python",
166166
"nbconvert_exporter": "python",
167-
"pygments_lexer": "ipython2",
168-
"version": "2.7.11"
167+
"pygments_lexer": "ipython3",
168+
"version": "3.5.1"
169169
}
170170
},
171171
"nbformat": 4,

‎LABS/LAB 3. Python Lists.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,21 +105,21 @@
105105
],
106106
"metadata": {
107107
"kernelspec": {
108-
"display_name": "Python 2",
108+
"display_name": "Python 3",
109109
"language": "python",
110-
"name": "python2"
110+
"name": "python3"
111111
},
112112
"language_info": {
113113
"codemirror_mode": {
114114
"name": "ipython",
115-
"version": 2
115+
"version": 3
116116
},
117117
"file_extension": ".py",
118118
"mimetype": "text/x-python",
119119
"name": "python",
120120
"nbconvert_exporter": "python",
121-
"pygments_lexer": "ipython2",
122-
"version": "2.7.11"
121+
"pygments_lexer": "ipython3",
122+
"version": "3.5.1"
123123
}
124124
},
125125
"nbformat": 4,

‎LABS/LAB 4. Subsetting Lists.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,21 +117,21 @@
117117
],
118118
"metadata": {
119119
"kernelspec": {
120-
"display_name": "Python 2",
120+
"display_name": "Python 3",
121121
"language": "python",
122-
"name": "python2"
122+
"name": "python3"
123123
},
124124
"language_info": {
125125
"codemirror_mode": {
126126
"name": "ipython",
127-
"version": 2
127+
"version": 3
128128
},
129129
"file_extension": ".py",
130130
"mimetype": "text/x-python",
131131
"name": "python",
132132
"nbconvert_exporter": "python",
133-
"pygments_lexer": "ipython2",
134-
"version": "2.7.11"
133+
"pygments_lexer": "ipython3",
134+
"version": "3.5.1"
135135
}
136136
},
137137
"nbformat": 4,

‎LABS/LAB 5. Manipulating Lists.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,21 @@
7777
],
7878
"metadata": {
7979
"kernelspec": {
80-
"display_name": "Python 2",
80+
"display_name": "Python 3",
8181
"language": "python",
82-
"name": "python2"
82+
"name": "python3"
8383
},
8484
"language_info": {
8585
"codemirror_mode": {
8686
"name": "ipython",
87-
"version": 2
87+
"version": 3
8888
},
8989
"file_extension": ".py",
9090
"mimetype": "text/x-python",
9191
"name": "python",
9292
"nbconvert_exporter": "python",
93-
"pygments_lexer": "ipython2",
94-
"version": "2.7.11"
93+
"pygments_lexer": "ipython3",
94+
"version": "3.5.1"
9595
}
9696
},
9797
"nbformat": 4,

‎LABS/LAB 9. Numpy.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,21 @@
144144
],
145145
"metadata": {
146146
"kernelspec": {
147-
"display_name": "Python 2",
147+
"display_name": "Python 3",
148148
"language": "python",
149-
"name": "python2"
149+
"name": "python3"
150150
},
151151
"language_info": {
152152
"codemirror_mode": {
153153
"name": "ipython",
154-
"version": 2
154+
"version": 3
155155
},
156156
"file_extension": ".py",
157157
"mimetype": "text/x-python",
158158
"name": "python",
159159
"nbconvert_exporter": "python",
160-
"pygments_lexer": "ipython2",
161-
"version": "2.7.11"
160+
"pygments_lexer": "ipython3",
161+
"version": "3.5.1"
162162
}
163163
},
164164
"nbformat": 4,
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"1. What is the characteristic about data visualization?\n",
8+
" - Visualization is a very powerful tool, both for exploring your data, as for reporting the results you come up with.\n",
9+
"2. What is the conventional way of importing the pyplot sub-package from the matplotlib package?\n",
10+
" - import matplotlib.pyplot as plt\n",
11+
"3. You are creating a line plot using the following code: a = [1, 2, 3, 4]; b = [3, 9, 2, 6]; plt.plot(a, b); plt.show()\n",
12+
" - The values in a are mapped onto the horizontal axis.\n",
13+
" - The values in b are mapped onto the vertical axis.\n",
14+
"4. Have another look at the code from the previous review question: a = [1, 2, 3, 4]; b = [3, 9, 2, 6]; plt.plot(a, b); plt.show()\n",
15+
" - Change plot() in plt.plot() to scatter().\n",
16+
"5. What is a characteristic of a histogram?\n",
17+
" - Histograms are a great tool to get a first idea about the distribution of your data.\n",
18+
"6. Suppose you have a Python list with 10 different values. You decide to divide the values into 5 equally-sized bins. How wide will these bins be if the lowest value in your list is 0 and the highest is 20?\n",
19+
" - 4\n",
20+
"7. Have a look at the following code sample: import matplotlib.pyplot as plt; x = [1, 3, 6, 3, 2, 7, 3, 9, 7, 5, 2, 4]; plt.hist(x); plt.show(). If you do not specify the number of bins the data has to be divided into, matplotlib chooses a suitable number of bins for you. How should you extend the plt.hist() command to specifically set the number of bins to 4?\n",
21+
" - Add a second argument to plt.hist(): plt.hist(x, bins = 4)\n",
22+
"8. A typical step when you're customizing a plot is labelling your axes. How can you do this with matplotlib?\n",
23+
" - xlabel(\"x-axis title\") and ylabel(\"y-axis title\")\n",
24+
"9. What is the name of the matplotlib function to build a line plot where the area under the graph is colored?\n",
25+
" - fill_between()\n",
26+
"10. Filip specifically mentioned that you should place all customization commands between the plot() call and the show() call, like this: import matplotlib.pyplot as plt; x = [1, 2, 3]; y = [4, 5, 6]; plt.plot(x, y); # customization here; plt.show(). Suppose you decide to place the customization code after the show() function, as follows: import matplotlib.pyplot as plt; x = [1, 2, 3]; y = [4, 5, 6]; plt.plot(x, y); plt.show(); # customization here. What do you think will happen if you execute the Python code in this order?\n",
27+
" - Python doesn't throw an error, but you won't see your customizations. The show() function displays the plot you've built up until then. If the customizations come afterwards, there is no effect on the shown output."
28+
]
29+
}
30+
],
31+
"metadata": {
32+
"kernelspec": {
33+
"display_name": "Python 3",
34+
"language": "python",
35+
"name": "python3"
36+
},
37+
"language_info": {
38+
"codemirror_mode": {
39+
"name": "ipython",
40+
"version": 3
41+
},
42+
"file_extension": ".py",
43+
"mimetype": "text/x-python",
44+
"name": "python",
45+
"nbconvert_exporter": "python",
46+
"pygments_lexer": "ipython3",
47+
"version": "3.5.1"
48+
}
49+
},
50+
"nbformat": 4,
51+
"nbformat_minor": 0
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"1. Have a look at the following comparison: 5 >= 5. What is the result of this comparison?\n",
8+
" - True\n",
9+
"2. Have a look at the following comparison: 4 != 4. What is the result of this comparison?\n",
10+
" - False\n",
11+
"3. You can use the and operator to compare different booleans. What is the characteristic of the and operator?\n",
12+
" - The and operator returns True only if both operands are True. In other words, only True and True gives True.\n",
13+
"4. You can use the or operator to compare different booleans. What is the characteristic of the or operator?\n",
14+
" - The or operator returns True if at least one of the operands is True. In other words, True or False, False or True and True or True all result in True.\n",
15+
"5. Things get really interesting once you can use the results of comparisons and boolean operations in a control structure. Have a look at the example below: x = 5; if x > 6 : print(\"high\") else : print(\"low\"). What will be printed out if you execute this piece of code?\n",
16+
" - low\n",
17+
"6. If your control structures get more advanced, Python can take many different paths through your code. It is very important to understand how Python does this. Have a look at the following control structure: x = 7; if x > 6 : print(\"high\") elif x > 3 : print(\"ok\") else : print(\"low\"). What will be printed out if you execute this piece of code?\n",
18+
" - high\n",
19+
"7. How is a Pandas DataFrame different from a 2D Numpy array?\n",
20+
" - In Pandas, different columns can contain different types. In 2D Numpy arrays, this is not possible.\n",
21+
"8. What are two characteristics that describe Pandas DataFrame?\n",
22+
" - The rows correspond to observations.\n",
23+
" - The columns correspond to variables.\n",
24+
"9. Which Pandas function do you need to import data from a comma-separated value (CSV) file into a Pandas DataFrame?\n",
25+
" - read_csv()\n",
26+
"10. You can access data in a Pandas DataFrame in several ways. Which technique should you use to select an entire row by its row label?\n",
27+
" - loc"
28+
]
29+
}
30+
],
31+
"metadata": {
32+
"kernelspec": {
33+
"display_name": "Python 3",
34+
"language": "python",
35+
"name": "python3"
36+
},
37+
"language_info": {
38+
"codemirror_mode": {
39+
"name": "ipython",
40+
"version": 3
41+
},
42+
"file_extension": ".py",
43+
"mimetype": "text/x-python",
44+
"name": "python",
45+
"nbconvert_exporter": "python",
46+
"pygments_lexer": "ipython3",
47+
"version": "3.5.1"
48+
}
49+
},
50+
"nbformat": 4,
51+
"nbformat_minor": 0
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"1. What is the characteristic about data visualization?\n",
8+
" - Visualization is a very powerful tool, both for exploring your data, as for reporting the results you come up with.\n",
9+
"2. What is the conventional way of importing the pyplot sub-package from the matplotlib package?\n",
10+
" - import matplotlib.pyplot as plt\n",
11+
"3. You are creating a line plot using the following code: a = [1, 2, 3, 4]; b = [3, 9, 2, 6]; plt.plot(a, b); plt.show()\n",
12+
" - The values in a are mapped onto the horizontal axis.\n",
13+
" - The values in b are mapped onto the vertical axis.\n",
14+
"4. Have another look at the code from the previous review question: a = [1, 2, 3, 4]; b = [3, 9, 2, 6]; plt.plot(a, b); plt.show()\n",
15+
" - Change plot() in plt.plot() to scatter().\n",
16+
"5. What is a characteristic of a histogram?\n",
17+
" - Histograms are a great tool to get a first idea about the distribution of your data.\n",
18+
"6. Suppose you have a Python list with 10 different values. You decide to divide the values into 5 equally-sized bins. How wide will these bins be if the lowest value in your list is 0 and the highest is 20?\n",
19+
" - 4\n",
20+
"7. Have a look at the following code sample: import matplotlib.pyplot as plt; x = [1, 3, 6, 3, 2, 7, 3, 9, 7, 5, 2, 4]; plt.hist(x); plt.show(). If you do not specify the number of bins the data has to be divided into, matplotlib chooses a suitable number of bins for you. How should you extend the plt.hist() command to specifically set the number of bins to 4?\n",
21+
" - Add a second argument to plt.hist(): plt.hist(x, bins = 4)\n",
22+
"8. A typical step when you're customizing a plot is labelling your axes. How can you do this with matplotlib?\n",
23+
" - xlabel(\"x-axis title\") and ylabel(\"y-axis title\")\n",
24+
"9. What is the name of the matplotlib function to build a line plot where the area under the graph is colored?\n",
25+
" - fill_between()\n",
26+
"10. Filip specifically mentioned that you should place all customization commands between the plot() call and the show() call, like this: import matplotlib.pyplot as plt; x = [1, 2, 3]; y = [4, 5, 6]; plt.plot(x, y); # customization here; plt.show(). Suppose you decide to place the customization code after the show() function, as follows: import matplotlib.pyplot as plt; x = [1, 2, 3]; y = [4, 5, 6]; plt.plot(x, y); plt.show(); # customization here. What do you think will happen if you execute the Python code in this order?\n",
27+
" - Python doesn't throw an error, but you won't see your customizations. The show() function displays the plot you've built up until then. If the customizations come afterwards, there is no effect on the shown output."
28+
]
29+
}
30+
],
31+
"metadata": {
32+
"kernelspec": {
33+
"display_name": "Python 3",
34+
"language": "python",
35+
"name": "python3"
36+
},
37+
"language_info": {
38+
"codemirror_mode": {
39+
"name": "ipython",
40+
"version": 3
41+
},
42+
"file_extension": ".py",
43+
"mimetype": "text/x-python",
44+
"name": "python",
45+
"nbconvert_exporter": "python",
46+
"pygments_lexer": "ipython3",
47+
"version": "3.5.1"
48+
}
49+
},
50+
"nbformat": 4,
51+
"nbformat_minor": 0
52+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"1. Have a look at the following comparison: 5 >= 5. What is the result of this comparison?\n",
8+
" - True\n",
9+
"2. Have a look at the following comparison: 4 != 4. What is the result of this comparison?\n",
10+
" - False\n",
11+
"3. You can use the and operator to compare different booleans. What is the characteristic of the and operator?\n",
12+
" - The and operator returns True only if both operands are True. In other words, only True and True gives True.\n",
13+
"4. You can use the or operator to compare different booleans. What is the characteristic of the or operator?\n",
14+
" - The or operator returns True if at least one of the operands is True. In other words, True or False, False or True and True or True all result in True.\n",
15+
"5. Things get really interesting once you can use the results of comparisons and boolean operations in a control structure. Have a look at the example below: x = 5; if x > 6 : print(\"high\") else : print(\"low\"). What will be printed out if you execute this piece of code?\n",
16+
" - low\n",
17+
"6. If your control structures get more advanced, Python can take many different paths through your code. It is very important to understand how Python does this. Have a look at the following control structure: x = 7; if x > 6 : print(\"high\") elif x > 3 : print(\"ok\") else : print(\"low\"). What will be printed out if you execute this piece of code?\n",
18+
" - high\n",
19+
"7. How is a Pandas DataFrame different from a 2D Numpy array?\n",
20+
" - In Pandas, different columns can contain different types. In 2D Numpy arrays, this is not possible.\n",
21+
"8. What are two characteristics that describe Pandas DataFrame?\n",
22+
" - The rows correspond to observations.\n",
23+
" - The columns correspond to variables.\n",
24+
"9. Which Pandas function do you need to import data from a comma-separated value (CSV) file into a Pandas DataFrame?\n",
25+
" - read_csv()\n",
26+
"10. You can access data in a Pandas DataFrame in several ways. Which technique should you use to select an entire row by its row label?\n",
27+
" - loc"
28+
]
29+
}
30+
],
31+
"metadata": {
32+
"kernelspec": {
33+
"display_name": "Python 3",
34+
"language": "python",
35+
"name": "python3"
36+
},
37+
"language_info": {
38+
"codemirror_mode": {
39+
"name": "ipython",
40+
"version": 3
41+
},
42+
"file_extension": ".py",
43+
"mimetype": "text/x-python",
44+
"name": "python",
45+
"nbconvert_exporter": "python",
46+
"pygments_lexer": "ipython3",
47+
"version": "3.5.1"
48+
}
49+
},
50+
"nbformat": 4,
51+
"nbformat_minor": 0
52+
}

0 commit comments

Comments
 (0)
Please sign in to comment.