Skip to content

Commit 285dead

Browse files
committed
Excercise - 5
1 parent 5a14448 commit 285dead

File tree

2 files changed

+368
-0
lines changed

2 files changed

+368
-0
lines changed

Chapter 1/.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 368 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,368 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"### 1.\tImport the pandas and load the two dataset(mark.csv and student.csv) into the pandas dataframe. "
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 1,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"import pandas as pd\n",
17+
"df1 = pd.read_csv('../Data/mark.csv',header = 0)\n",
18+
"df2 = pd.read_csv('../Data/student.csv',header = 0)"
19+
]
20+
},
21+
{
22+
"cell_type": "markdown",
23+
"metadata": {},
24+
"source": [
25+
"### 2.\tPrint out the top 5 rows of df1"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": 8,
31+
"metadata": {},
32+
"outputs": [
33+
{
34+
"data": {
35+
"text/html": [
36+
"<div>\n",
37+
"<style scoped>\n",
38+
" .dataframe tbody tr th:only-of-type {\n",
39+
" vertical-align: middle;\n",
40+
" }\n",
41+
"\n",
42+
" .dataframe tbody tr th {\n",
43+
" vertical-align: top;\n",
44+
" }\n",
45+
"\n",
46+
" .dataframe thead th {\n",
47+
" text-align: right;\n",
48+
" }\n",
49+
"</style>\n",
50+
"<table border=\"1\" class=\"dataframe\">\n",
51+
" <thead>\n",
52+
" <tr style=\"text-align: right;\">\n",
53+
" <th></th>\n",
54+
" <th>Student_id</th>\n",
55+
" <th>Mark</th>\n",
56+
" <th>City</th>\n",
57+
" </tr>\n",
58+
" </thead>\n",
59+
" <tbody>\n",
60+
" <tr>\n",
61+
" <th>0</th>\n",
62+
" <td>1</td>\n",
63+
" <td>95</td>\n",
64+
" <td>Chennai</td>\n",
65+
" </tr>\n",
66+
" <tr>\n",
67+
" <th>1</th>\n",
68+
" <td>2</td>\n",
69+
" <td>70</td>\n",
70+
" <td>Delhi</td>\n",
71+
" </tr>\n",
72+
" <tr>\n",
73+
" <th>2</th>\n",
74+
" <td>3</td>\n",
75+
" <td>98</td>\n",
76+
" <td>Mumbai</td>\n",
77+
" </tr>\n",
78+
" <tr>\n",
79+
" <th>3</th>\n",
80+
" <td>4</td>\n",
81+
" <td>75</td>\n",
82+
" <td>Pune</td>\n",
83+
" </tr>\n",
84+
" <tr>\n",
85+
" <th>4</th>\n",
86+
" <td>5</td>\n",
87+
" <td>89</td>\n",
88+
" <td>Kochi</td>\n",
89+
" </tr>\n",
90+
" </tbody>\n",
91+
"</table>\n",
92+
"</div>"
93+
],
94+
"text/plain": [
95+
" Student_id Mark City\n",
96+
"0 1 95 Chennai\n",
97+
"1 2 70 Delhi\n",
98+
"2 3 98 Mumbai\n",
99+
"3 4 75 Pune\n",
100+
"4 5 89 Kochi"
101+
]
102+
},
103+
"execution_count": 8,
104+
"metadata": {},
105+
"output_type": "execute_result"
106+
}
107+
],
108+
"source": [
109+
"df1.head()"
110+
]
111+
},
112+
{
113+
"cell_type": "markdown",
114+
"metadata": {},
115+
"source": [
116+
"### 3.\tPrint out the top 5 rows of df2"
117+
]
118+
},
119+
{
120+
"cell_type": "code",
121+
"execution_count": 4,
122+
"metadata": {},
123+
"outputs": [
124+
{
125+
"data": {
126+
"text/html": [
127+
"<div>\n",
128+
"<style scoped>\n",
129+
" .dataframe tbody tr th:only-of-type {\n",
130+
" vertical-align: middle;\n",
131+
" }\n",
132+
"\n",
133+
" .dataframe tbody tr th {\n",
134+
" vertical-align: top;\n",
135+
" }\n",
136+
"\n",
137+
" .dataframe thead th {\n",
138+
" text-align: right;\n",
139+
" }\n",
140+
"</style>\n",
141+
"<table border=\"1\" class=\"dataframe\">\n",
142+
" <thead>\n",
143+
" <tr style=\"text-align: right;\">\n",
144+
" <th></th>\n",
145+
" <th>Student_id</th>\n",
146+
" <th>Age</th>\n",
147+
" <th>Gender</th>\n",
148+
" <th>Grade</th>\n",
149+
" <th>Employed</th>\n",
150+
" </tr>\n",
151+
" </thead>\n",
152+
" <tbody>\n",
153+
" <tr>\n",
154+
" <th>0</th>\n",
155+
" <td>1</td>\n",
156+
" <td>19</td>\n",
157+
" <td>Male</td>\n",
158+
" <td>1st Class</td>\n",
159+
" <td>yes</td>\n",
160+
" </tr>\n",
161+
" <tr>\n",
162+
" <th>1</th>\n",
163+
" <td>2</td>\n",
164+
" <td>20</td>\n",
165+
" <td>Female</td>\n",
166+
" <td>2nd Class</td>\n",
167+
" <td>no</td>\n",
168+
" </tr>\n",
169+
" <tr>\n",
170+
" <th>2</th>\n",
171+
" <td>3</td>\n",
172+
" <td>18</td>\n",
173+
" <td>Male</td>\n",
174+
" <td>1st Class</td>\n",
175+
" <td>no</td>\n",
176+
" </tr>\n",
177+
" <tr>\n",
178+
" <th>3</th>\n",
179+
" <td>4</td>\n",
180+
" <td>21</td>\n",
181+
" <td>Female</td>\n",
182+
" <td>2nd Class</td>\n",
183+
" <td>no</td>\n",
184+
" </tr>\n",
185+
" <tr>\n",
186+
" <th>4</th>\n",
187+
" <td>5</td>\n",
188+
" <td>19</td>\n",
189+
" <td>Male</td>\n",
190+
" <td>1st Class</td>\n",
191+
" <td>no</td>\n",
192+
" </tr>\n",
193+
" </tbody>\n",
194+
"</table>\n",
195+
"</div>"
196+
],
197+
"text/plain": [
198+
" Student_id Age Gender Grade Employed\n",
199+
"0 1 19 Male 1st Class yes\n",
200+
"1 2 20 Female 2nd Class no\n",
201+
"2 3 18 Male 1st Class no\n",
202+
"3 4 21 Female 2nd Class no\n",
203+
"4 5 19 Male 1st Class no"
204+
]
205+
},
206+
"execution_count": 4,
207+
"metadata": {},
208+
"output_type": "execute_result"
209+
}
210+
],
211+
"source": [
212+
"df2.head()"
213+
]
214+
},
215+
{
216+
"cell_type": "markdown",
217+
"metadata": {},
218+
"source": [
219+
"### 4.\tPerform data integration to both the dataframe with respect to the column ‘Student_id’ key word ‘pd.merge()’"
220+
]
221+
},
222+
{
223+
"cell_type": "code",
224+
"execution_count": 5,
225+
"metadata": {},
226+
"outputs": [],
227+
"source": [
228+
"df = pd.merge(df1, df2, on = 'Student_id')"
229+
]
230+
},
231+
{
232+
"cell_type": "markdown",
233+
"metadata": {},
234+
"source": [
235+
"### 5.\tPrint out the top 5 rows of df"
236+
]
237+
},
238+
{
239+
"cell_type": "code",
240+
"execution_count": 10,
241+
"metadata": {},
242+
"outputs": [
243+
{
244+
"data": {
245+
"text/html": [
246+
"<div>\n",
247+
"<style scoped>\n",
248+
" .dataframe tbody tr th:only-of-type {\n",
249+
" vertical-align: middle;\n",
250+
" }\n",
251+
"\n",
252+
" .dataframe tbody tr th {\n",
253+
" vertical-align: top;\n",
254+
" }\n",
255+
"\n",
256+
" .dataframe thead th {\n",
257+
" text-align: right;\n",
258+
" }\n",
259+
"</style>\n",
260+
"<table border=\"1\" class=\"dataframe\">\n",
261+
" <thead>\n",
262+
" <tr style=\"text-align: right;\">\n",
263+
" <th></th>\n",
264+
" <th>Student_id</th>\n",
265+
" <th>Mark</th>\n",
266+
" <th>City</th>\n",
267+
" <th>Age</th>\n",
268+
" <th>Gender</th>\n",
269+
" <th>Grade</th>\n",
270+
" <th>Employed</th>\n",
271+
" </tr>\n",
272+
" </thead>\n",
273+
" <tbody>\n",
274+
" <tr>\n",
275+
" <th>0</th>\n",
276+
" <td>1</td>\n",
277+
" <td>95</td>\n",
278+
" <td>Chennai</td>\n",
279+
" <td>19</td>\n",
280+
" <td>Male</td>\n",
281+
" <td>1st Class</td>\n",
282+
" <td>yes</td>\n",
283+
" </tr>\n",
284+
" <tr>\n",
285+
" <th>1</th>\n",
286+
" <td>2</td>\n",
287+
" <td>70</td>\n",
288+
" <td>Delhi</td>\n",
289+
" <td>20</td>\n",
290+
" <td>Female</td>\n",
291+
" <td>2nd Class</td>\n",
292+
" <td>no</td>\n",
293+
" </tr>\n",
294+
" <tr>\n",
295+
" <th>2</th>\n",
296+
" <td>3</td>\n",
297+
" <td>98</td>\n",
298+
" <td>Mumbai</td>\n",
299+
" <td>18</td>\n",
300+
" <td>Male</td>\n",
301+
" <td>1st Class</td>\n",
302+
" <td>no</td>\n",
303+
" </tr>\n",
304+
" <tr>\n",
305+
" <th>3</th>\n",
306+
" <td>4</td>\n",
307+
" <td>75</td>\n",
308+
" <td>Pune</td>\n",
309+
" <td>21</td>\n",
310+
" <td>Female</td>\n",
311+
" <td>2nd Class</td>\n",
312+
" <td>no</td>\n",
313+
" </tr>\n",
314+
" <tr>\n",
315+
" <th>4</th>\n",
316+
" <td>5</td>\n",
317+
" <td>89</td>\n",
318+
" <td>Kochi</td>\n",
319+
" <td>19</td>\n",
320+
" <td>Male</td>\n",
321+
" <td>1st Class</td>\n",
322+
" <td>no</td>\n",
323+
" </tr>\n",
324+
" </tbody>\n",
325+
"</table>\n",
326+
"</div>"
327+
],
328+
"text/plain": [
329+
" Student_id Mark City Age Gender Grade Employed\n",
330+
"0 1 95 Chennai 19 Male 1st Class yes\n",
331+
"1 2 70 Delhi 20 Female 2nd Class no\n",
332+
"2 3 98 Mumbai 18 Male 1st Class no\n",
333+
"3 4 75 Pune 21 Female 2nd Class no\n",
334+
"4 5 89 Kochi 19 Male 1st Class no"
335+
]
336+
},
337+
"execution_count": 10,
338+
"metadata": {},
339+
"output_type": "execute_result"
340+
}
341+
],
342+
"source": [
343+
"df.head()"
344+
]
345+
}
346+
],
347+
"metadata": {
348+
"kernelspec": {
349+
"display_name": "Python 3",
350+
"language": "python",
351+
"name": "python3"
352+
},
353+
"language_info": {
354+
"codemirror_mode": {
355+
"name": "ipython",
356+
"version": 3
357+
},
358+
"file_extension": ".py",
359+
"mimetype": "text/x-python",
360+
"name": "python",
361+
"nbconvert_exporter": "python",
362+
"pygments_lexer": "ipython3",
363+
"version": "3.6.4"
364+
}
365+
},
366+
"nbformat": 4,
367+
"nbformat_minor": 2
368+
}

0 commit comments

Comments
 (0)