Skip to content

Commit fd8a9ae

Browse files
committed
Analyst exercise 1
1 parent 32a58cd commit fd8a9ae

File tree

1 file changed

+275
-9
lines changed

1 file changed

+275
-9
lines changed

example_report/practice_exercise1_Julia.ipynb

+275-9
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,290 @@
4848
},
4949
{
5050
"cell_type": "code",
51-
"execution_count": 62,
51+
"execution_count": 253,
52+
"id": "656a2fa1-35e5-47e2-98fa-a6e1c9770f8f",
53+
"metadata": {},
54+
"outputs": [
55+
{
56+
"data": {
57+
"text/html": [
58+
"<div>\n",
59+
"<style scoped>\n",
60+
" .dataframe tbody tr th:only-of-type {\n",
61+
" vertical-align: middle;\n",
62+
" }\n",
63+
"\n",
64+
" .dataframe tbody tr th {\n",
65+
" vertical-align: top;\n",
66+
" }\n",
67+
"\n",
68+
" .dataframe thead th {\n",
69+
" text-align: right;\n",
70+
" }\n",
71+
"</style>\n",
72+
"<table border=\"1\" class=\"dataframe\">\n",
73+
" <thead>\n",
74+
" <tr style=\"text-align: right;\">\n",
75+
" <th></th>\n",
76+
" <th>mpg</th>\n",
77+
" <th>cyl</th>\n",
78+
" <th>disp</th>\n",
79+
" <th>hp</th>\n",
80+
" <th>drat</th>\n",
81+
" <th>wt</th>\n",
82+
" <th>qsec</th>\n",
83+
" <th>vs</th>\n",
84+
" <th>am</th>\n",
85+
" <th>gear</th>\n",
86+
" <th>carb</th>\n",
87+
" <th>cylinder_flag1</th>\n",
88+
" </tr>\n",
89+
" </thead>\n",
90+
" <tbody>\n",
91+
" <tr>\n",
92+
" <th>0</th>\n",
93+
" <td>21.0</td>\n",
94+
" <td>6</td>\n",
95+
" <td>160.0</td>\n",
96+
" <td>110</td>\n",
97+
" <td>3.90</td>\n",
98+
" <td>2.620</td>\n",
99+
" <td>16.46</td>\n",
100+
" <td>0</td>\n",
101+
" <td>1</td>\n",
102+
" <td>4</td>\n",
103+
" <td>4</td>\n",
104+
" <td>six</td>\n",
105+
" </tr>\n",
106+
" <tr>\n",
107+
" <th>1</th>\n",
108+
" <td>21.0</td>\n",
109+
" <td>6</td>\n",
110+
" <td>160.0</td>\n",
111+
" <td>110</td>\n",
112+
" <td>3.90</td>\n",
113+
" <td>2.875</td>\n",
114+
" <td>17.02</td>\n",
115+
" <td>0</td>\n",
116+
" <td>1</td>\n",
117+
" <td>4</td>\n",
118+
" <td>4</td>\n",
119+
" <td>six</td>\n",
120+
" </tr>\n",
121+
" <tr>\n",
122+
" <th>2</th>\n",
123+
" <td>22.8</td>\n",
124+
" <td>4</td>\n",
125+
" <td>108.0</td>\n",
126+
" <td>93</td>\n",
127+
" <td>3.85</td>\n",
128+
" <td>2.320</td>\n",
129+
" <td>18.61</td>\n",
130+
" <td>1</td>\n",
131+
" <td>1</td>\n",
132+
" <td>4</td>\n",
133+
" <td>1</td>\n",
134+
" <td>other</td>\n",
135+
" </tr>\n",
136+
" <tr>\n",
137+
" <th>3</th>\n",
138+
" <td>21.4</td>\n",
139+
" <td>6</td>\n",
140+
" <td>258.0</td>\n",
141+
" <td>110</td>\n",
142+
" <td>3.08</td>\n",
143+
" <td>3.215</td>\n",
144+
" <td>19.44</td>\n",
145+
" <td>1</td>\n",
146+
" <td>0</td>\n",
147+
" <td>3</td>\n",
148+
" <td>1</td>\n",
149+
" <td>six</td>\n",
150+
" </tr>\n",
151+
" <tr>\n",
152+
" <th>4</th>\n",
153+
" <td>18.7</td>\n",
154+
" <td>8</td>\n",
155+
" <td>360.0</td>\n",
156+
" <td>175</td>\n",
157+
" <td>3.15</td>\n",
158+
" <td>3.440</td>\n",
159+
" <td>17.02</td>\n",
160+
" <td>0</td>\n",
161+
" <td>0</td>\n",
162+
" <td>3</td>\n",
163+
" <td>2</td>\n",
164+
" <td>other</td>\n",
165+
" </tr>\n",
166+
" </tbody>\n",
167+
"</table>\n",
168+
"</div>"
169+
],
170+
"text/plain": [
171+
" mpg cyl disp hp drat wt qsec vs am gear carb \\\n",
172+
"0 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 \n",
173+
"1 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 \n",
174+
"2 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 \n",
175+
"3 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 \n",
176+
"4 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 \n",
177+
"\n",
178+
" cylinder_flag1 \n",
179+
"0 six \n",
180+
"1 six \n",
181+
"2 other \n",
182+
"3 six \n",
183+
"4 other "
184+
]
185+
},
186+
"execution_count": 253,
187+
"metadata": {},
188+
"output_type": "execute_result"
189+
}
190+
],
191+
"source": [
192+
"mtcars.head()"
193+
]
194+
},
195+
{
196+
"cell_type": "code",
197+
"execution_count": 260,
52198
"id": "1ffb5075-655e-4180-ba7b-d61c138bd6cf",
53199
"metadata": {},
54200
"outputs": [
55201
{
56-
"name": "stdout",
57-
"output_type": "stream",
58-
"text": [
59-
"The average mpg is 20.090624999999996.\n",
60-
"The difference between max and min weight is 3.9110000000000005.\n"
61-
]
202+
"data": {
203+
"text/html": [
204+
"<div>\n",
205+
"<style scoped>\n",
206+
" .dataframe tbody tr th:only-of-type {\n",
207+
" vertical-align: middle;\n",
208+
" }\n",
209+
"\n",
210+
" .dataframe tbody tr th {\n",
211+
" vertical-align: top;\n",
212+
" }\n",
213+
"\n",
214+
" .dataframe thead th {\n",
215+
" text-align: right;\n",
216+
" }\n",
217+
"</style>\n",
218+
"<table border=\"1\" class=\"dataframe\">\n",
219+
" <thead>\n",
220+
" <tr style=\"text-align: right;\">\n",
221+
" <th></th>\n",
222+
" <th>cyl</th>\n",
223+
" <th>avg_mpg</th>\n",
224+
" </tr>\n",
225+
" </thead>\n",
226+
" <tbody>\n",
227+
" <tr>\n",
228+
" <th>0</th>\n",
229+
" <td>4</td>\n",
230+
" <td>26.663636</td>\n",
231+
" </tr>\n",
232+
" <tr>\n",
233+
" <th>1</th>\n",
234+
" <td>6</td>\n",
235+
" <td>19.742857</td>\n",
236+
" </tr>\n",
237+
" <tr>\n",
238+
" <th>2</th>\n",
239+
" <td>8</td>\n",
240+
" <td>15.100000</td>\n",
241+
" </tr>\n",
242+
" </tbody>\n",
243+
"</table>\n",
244+
"</div>"
245+
],
246+
"text/plain": [
247+
" cyl avg_mpg\n",
248+
"0 4 26.663636\n",
249+
"1 6 19.742857\n",
250+
"2 8 15.100000"
251+
]
252+
},
253+
"execution_count": 260,
254+
"metadata": {},
255+
"output_type": "execute_result"
62256
}
63257
],
64258
"source": [
65259
"#Average mpg\n",
66260
"\n",
67-
"print(f\"The average mpg is {mtcars.mpg.mean()}.\")\n",
68-
"print(f\"The difference between max and min weight is {mtcars.wt.max() - mtcars.wt.min()}.\")"
261+
"# For all cyl -print(f\"The average mpg is {mtcars.mpg.mean()}.\")\n",
262+
"\n",
263+
"mtcars >> group_by(_.cyl) >> summarize(avg_mpg = _.mpg.mean()) >> ungroup()\n",
264+
"\n"
265+
]
266+
},
267+
{
268+
"cell_type": "code",
269+
"execution_count": 262,
270+
"id": "bdd08b36-f0da-4fe5-a54c-055349de4c20",
271+
"metadata": {},
272+
"outputs": [
273+
{
274+
"data": {
275+
"text/html": [
276+
"<div>\n",
277+
"<style scoped>\n",
278+
" .dataframe tbody tr th:only-of-type {\n",
279+
" vertical-align: middle;\n",
280+
" }\n",
281+
"\n",
282+
" .dataframe tbody tr th {\n",
283+
" vertical-align: top;\n",
284+
" }\n",
285+
"\n",
286+
" .dataframe thead th {\n",
287+
" text-align: right;\n",
288+
" }\n",
289+
"</style>\n",
290+
"<table border=\"1\" class=\"dataframe\">\n",
291+
" <thead>\n",
292+
" <tr style=\"text-align: right;\">\n",
293+
" <th></th>\n",
294+
" <th>cyl</th>\n",
295+
" <th>diff_wt</th>\n",
296+
" </tr>\n",
297+
" </thead>\n",
298+
" <tbody>\n",
299+
" <tr>\n",
300+
" <th>0</th>\n",
301+
" <td>4</td>\n",
302+
" <td>1.677</td>\n",
303+
" </tr>\n",
304+
" <tr>\n",
305+
" <th>1</th>\n",
306+
" <td>6</td>\n",
307+
" <td>0.840</td>\n",
308+
" </tr>\n",
309+
" <tr>\n",
310+
" <th>2</th>\n",
311+
" <td>8</td>\n",
312+
" <td>2.254</td>\n",
313+
" </tr>\n",
314+
" </tbody>\n",
315+
"</table>\n",
316+
"</div>"
317+
],
318+
"text/plain": [
319+
" cyl diff_wt\n",
320+
"0 4 1.677\n",
321+
"1 6 0.840\n",
322+
"2 8 2.254"
323+
]
324+
},
325+
"execution_count": 262,
326+
"metadata": {},
327+
"output_type": "execute_result"
328+
}
329+
],
330+
"source": [
331+
"#Difference\n",
332+
"# For all cyl - print(f\"The difference between max and min weight is {mtcars.wt.max() - mtcars.wt.min()}.\")\n",
333+
"\n",
334+
"mtcars >> group_by(_.cyl) >> summarize(diff_wt = _.wt.max() - _.wt.min()) >> ungroup()"
69335
]
70336
},
71337
{

0 commit comments

Comments
 (0)