zxy0307 commited on
Commit
7998276
·
verified ·
1 Parent(s): 74880ed

Upload 30 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ 人工智能-第1阶段Python基础.pdf filter=lfs diff=lfs merge=lfs -text
37
+ 人工智能-第1阶段python进阶和高级编程.pdf filter=lfs diff=lfs merge=lfs -text
01_python的概念与变量.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
02_python判断语句.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
03_python循环语句.ipynb ADDED
@@ -0,0 +1,436 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "## while循环"
8
+ ]
9
+ },
10
+ {
11
+ "cell_type": "code",
12
+ "execution_count": 2,
13
+ "metadata": {
14
+ "ExecuteTime": {
15
+ "end_time": "2023-07-21T23:51:47.441472Z",
16
+ "start_time": "2023-07-21T23:51:47.437236Z"
17
+ }
18
+ },
19
+ "outputs": [
20
+ {
21
+ "name": "stdout",
22
+ "output_type": "stream",
23
+ "text": [
24
+ "0\n",
25
+ "1\n",
26
+ "2\n",
27
+ "3\n",
28
+ "4\n",
29
+ "5\n",
30
+ "6\n",
31
+ "7\n",
32
+ "8\n",
33
+ "9\n"
34
+ ]
35
+ }
36
+ ],
37
+ "source": [
38
+ "count = 0\n",
39
+ "\n",
40
+ "while count <= 9:\n",
41
+ " print(count)\n",
42
+ " count += 1 # count = count + 1"
43
+ ]
44
+ },
45
+ {
46
+ "cell_type": "markdown",
47
+ "metadata": {},
48
+ "source": [
49
+ "不想每打印一个数 就打印一次回车:"
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "execution_count": 3,
55
+ "metadata": {
56
+ "ExecuteTime": {
57
+ "end_time": "2023-07-21T23:53:14.397046Z",
58
+ "start_time": "2023-07-21T23:53:14.393478Z"
59
+ }
60
+ },
61
+ "outputs": [
62
+ {
63
+ "name": "stdout",
64
+ "output_type": "stream",
65
+ "text": [
66
+ "0 1 2 3 4 5 6 7 8 9 \n"
67
+ ]
68
+ }
69
+ ],
70
+ "source": [
71
+ "# 字符串拼接法\n",
72
+ "\n",
73
+ "result = ''\n",
74
+ "count = 0\n",
75
+ "\n",
76
+ "while count <= 9:\n",
77
+ " result += (str(count) + ' ')\n",
78
+ " count += 1 # count = count + 1\n",
79
+ " \n",
80
+ "print(result)"
81
+ ]
82
+ },
83
+ {
84
+ "cell_type": "code",
85
+ "execution_count": 11,
86
+ "metadata": {},
87
+ "outputs": [
88
+ {
89
+ "name": "stdout",
90
+ "output_type": "stream",
91
+ "text": [
92
+ "0 1 2 3 4 5 6 7 8 9 end\n"
93
+ ]
94
+ }
95
+ ],
96
+ "source": [
97
+ "# 令 end=' '\n",
98
+ "\n",
99
+ "count = 0\n",
100
+ "\n",
101
+ "while count <= 9:\n",
102
+ " print(count, end=' ') # 参数end: 打印完内容后,再打印 end内容,默认‘\\n’\n",
103
+ " count += 1\n",
104
+ "\n",
105
+ "print('end')"
106
+ ]
107
+ },
108
+ {
109
+ "cell_type": "code",
110
+ "execution_count": 4,
111
+ "metadata": {
112
+ "ExecuteTime": {
113
+ "end_time": "2023-07-21T23:53:52.356563Z",
114
+ "start_time": "2023-07-21T23:53:52.352684Z"
115
+ }
116
+ },
117
+ "outputs": [
118
+ {
119
+ "name": "stdout",
120
+ "output_type": "stream",
121
+ "text": [
122
+ "0 1 2 3 4 5 6 7 8 9 \n",
123
+ "Done\n"
124
+ ]
125
+ }
126
+ ],
127
+ "source": [
128
+ "count = 0\n",
129
+ "\n",
130
+ "while count <= 9:\n",
131
+ " print(count, end=' ') \n",
132
+ " count += 1 # count = count + 1\n",
133
+ " \n",
134
+ "print() # 换行\n",
135
+ "print('Done')"
136
+ ]
137
+ },
138
+ {
139
+ "cell_type": "markdown",
140
+ "metadata": {},
141
+ "source": [
142
+ "## while...else语句"
143
+ ]
144
+ },
145
+ {
146
+ "cell_type": "code",
147
+ "execution_count": 5,
148
+ "metadata": {
149
+ "ExecuteTime": {
150
+ "end_time": "2023-07-21T23:58:48.097742Z",
151
+ "start_time": "2023-07-21T23:58:48.093531Z"
152
+ }
153
+ },
154
+ "outputs": [
155
+ {
156
+ "name": "stdout",
157
+ "output_type": "stream",
158
+ "text": [
159
+ "0 1 2 3 4 5 6 7 8 9 end\n"
160
+ ]
161
+ }
162
+ ],
163
+ "source": [
164
+ "# while语句执行完之后,自动执行 else里的内容\n",
165
+ "\n",
166
+ "count = 0\n",
167
+ "\n",
168
+ "while count <= 9:\n",
169
+ " print(count, end=' ')\n",
170
+ " count += 1\n",
171
+ "\n",
172
+ "else:\n",
173
+ " print('end')"
174
+ ]
175
+ },
176
+ {
177
+ "cell_type": "markdown",
178
+ "metadata": {},
179
+ "source": [
180
+ "## for循环\n",
181
+ "每次循环,会从集合中取得一个元素,并执行一次代码块,直到集合中所有的元素都获取\n",
182
+ "\n",
183
+ "可以遍历的对象有:序列(字符串、列表、元组) 、字典、迭代器对象(iterator) 、生成器函数文件对象"
184
+ ]
185
+ },
186
+ {
187
+ "cell_type": "code",
188
+ "execution_count": 6,
189
+ "metadata": {
190
+ "ExecuteTime": {
191
+ "end_time": "2023-07-22T00:04:01.067009Z",
192
+ "start_time": "2023-07-22T00:04:01.061827Z"
193
+ }
194
+ },
195
+ "outputs": [
196
+ {
197
+ "name": "stdout",
198
+ "output_type": "stream",
199
+ "text": [
200
+ "Tom\n",
201
+ "Peter\n",
202
+ "Jerry\n",
203
+ "Jack\n"
204
+ ]
205
+ }
206
+ ],
207
+ "source": [
208
+ "# 列表 -- 可迭代对象\n",
209
+ "names = ['Tom', 'Peter', 'Jerry', 'Jack']\n",
210
+ "\n",
211
+ "# 遍历列表\n",
212
+ "for name in names:\n",
213
+ " print(name)"
214
+ ]
215
+ },
216
+ {
217
+ "cell_type": "code",
218
+ "execution_count": 8,
219
+ "metadata": {
220
+ "ExecuteTime": {
221
+ "end_time": "2023-07-22T00:06:44.788587Z",
222
+ "start_time": "2023-07-22T00:06:44.777995Z"
223
+ }
224
+ },
225
+ "outputs": [
226
+ {
227
+ "data": {
228
+ "text/plain": [
229
+ "[0, 1, 2, 3]"
230
+ ]
231
+ },
232
+ "execution_count": 8,
233
+ "metadata": {},
234
+ "output_type": "execute_result"
235
+ }
236
+ ],
237
+ "source": [
238
+ "# range():构造range对象,可迭代\n",
239
+ "# list():强转为列表类型\n",
240
+ "\n",
241
+ "list(range(4))"
242
+ ]
243
+ },
244
+ {
245
+ "cell_type": "code",
246
+ "execution_count": 9,
247
+ "metadata": {
248
+ "ExecuteTime": {
249
+ "end_time": "2023-07-22T00:07:39.214456Z",
250
+ "start_time": "2023-07-22T00:07:39.211134Z"
251
+ }
252
+ },
253
+ "outputs": [
254
+ {
255
+ "name": "stdout",
256
+ "output_type": "stream",
257
+ "text": [
258
+ "0 Tom\n",
259
+ "1 Peter\n",
260
+ "2 Jerry\n",
261
+ "3 Jack\n"
262
+ ]
263
+ }
264
+ ],
265
+ "source": [
266
+ "for i in range(len(names)): # len(names)为 4\n",
267
+ " \n",
268
+ " print(i, names[i])"
269
+ ]
270
+ },
271
+ {
272
+ "cell_type": "markdown",
273
+ "metadata": {},
274
+ "source": [
275
+ "## 循环嵌套"
276
+ ]
277
+ },
278
+ {
279
+ "cell_type": "markdown",
280
+ "metadata": {},
281
+ "source": [
282
+ "### while嵌套"
283
+ ]
284
+ },
285
+ {
286
+ "cell_type": "code",
287
+ "execution_count": 10,
288
+ "metadata": {
289
+ "ExecuteTime": {
290
+ "end_time": "2023-07-22T00:16:57.035071Z",
291
+ "start_time": "2023-07-22T00:16:57.029723Z"
292
+ }
293
+ },
294
+ "outputs": [
295
+ {
296
+ "name": "stdout",
297
+ "output_type": "stream",
298
+ "text": [
299
+ "1*1=1\t\n",
300
+ "2*1=2\t2*2=4\t\n",
301
+ "3*1=3\t3*2=6\t3*3=9\t\n",
302
+ "4*1=4\t4*2=8\t4*3=12\t4*4=16\t\n",
303
+ "5*1=5\t5*2=10\t5*3=15\t5*4=20\t5*5=25\t\n",
304
+ "6*1=6\t6*2=12\t6*3=18\t6*4=24\t6*5=30\t6*6=36\t\n",
305
+ "7*1=7\t7*2=14\t7*3=21\t7*4=28\t7*5=35\t7*6=42\t7*7=49\t\n",
306
+ "8*1=8\t8*2=16\t8*3=24\t8*4=32\t8*5=40\t8*6=48\t8*7=56\t8*8=64\t\n",
307
+ "9*1=9\t9*2=18\t9*3=27\t9*4=36\t9*5=45\t9*6=54\t9*7=63\t9*8=72\t9*9=81\t\n"
308
+ ]
309
+ }
310
+ ],
311
+ "source": [
312
+ "# 打印九九乘法表\n",
313
+ "j = 1\n",
314
+ "while j <= 9:\n",
315
+ " i = 1\n",
316
+ " \n",
317
+ " while i <= j:\n",
318
+ " \n",
319
+ " # 格式化输出\n",
320
+ " print(\"%d*%d=%d\"%(j, i, i*j), end='\\t')\n",
321
+ " i += 1\n",
322
+ " \n",
323
+ " print()\n",
324
+ " j += 1"
325
+ ]
326
+ },
327
+ {
328
+ "cell_type": "markdown",
329
+ "metadata": {},
330
+ "source": [
331
+ "### for嵌套"
332
+ ]
333
+ },
334
+ {
335
+ "cell_type": "code",
336
+ "execution_count": 22,
337
+ "metadata": {},
338
+ "outputs": [
339
+ {
340
+ "data": {
341
+ "text/plain": [
342
+ "[1, 3, 5, 7, 9]"
343
+ ]
344
+ },
345
+ "execution_count": 22,
346
+ "metadata": {},
347
+ "output_type": "execute_result"
348
+ }
349
+ ],
350
+ "source": [
351
+ "# 生成可迭代对象,step为2\n",
352
+ "list(range(1, 10, 2))"
353
+ ]
354
+ },
355
+ {
356
+ "cell_type": "code",
357
+ "execution_count": 11,
358
+ "metadata": {
359
+ "ExecuteTime": {
360
+ "end_time": "2023-07-22T00:20:30.266582Z",
361
+ "start_time": "2023-07-22T00:20:30.260596Z"
362
+ }
363
+ },
364
+ "outputs": [
365
+ {
366
+ "name": "stdout",
367
+ "output_type": "stream",
368
+ "text": [
369
+ "1*1=1\t\n",
370
+ "2*1=2\t2*2=4\t\n",
371
+ "3*1=3\t3*2=6\t3*3=9\t\n",
372
+ "4*1=4\t4*2=8\t4*3=12\t4*4=16\t\n",
373
+ "5*1=5\t5*2=10\t5*3=15\t5*4=20\t5*5=25\t\n",
374
+ "6*1=6\t6*2=12\t6*3=18\t6*4=24\t6*5=30\t6*6=36\t\n",
375
+ "7*1=7\t7*2=14\t7*3=21\t7*4=28\t7*5=35\t7*6=42\t7*7=49\t\n",
376
+ "8*1=8\t8*2=16\t8*3=24\t8*4=32\t8*5=40\t8*6=48\t8*7=56\t8*8=64\t\n",
377
+ "9*1=9\t9*2=18\t9*3=27\t9*4=36\t9*5=45\t9*6=54\t9*7=63\t9*8=72\t9*9=81\t\n"
378
+ ]
379
+ }
380
+ ],
381
+ "source": [
382
+ "# 左闭右开 [1, 10),step默认为1\n",
383
+ "for j in range(1, 10):\n",
384
+ " \n",
385
+ " for i in range(1, j+1):\n",
386
+ " print(\"%d*%d=%d\"%(j, i, i*j), end='\\t')\n",
387
+ " \n",
388
+ " print()"
389
+ ]
390
+ },
391
+ {
392
+ "cell_type": "markdown",
393
+ "metadata": {},
394
+ "source": []
395
+ }
396
+ ],
397
+ "metadata": {
398
+ "kernelspec": {
399
+ "display_name": "Python 3 (ipykernel)",
400
+ "language": "python",
401
+ "name": "python3"
402
+ },
403
+ "language_info": {
404
+ "codemirror_mode": {
405
+ "name": "ipython",
406
+ "version": 3
407
+ },
408
+ "file_extension": ".py",
409
+ "mimetype": "text/x-python",
410
+ "name": "python",
411
+ "nbconvert_exporter": "python",
412
+ "pygments_lexer": "ipython3",
413
+ "version": "3.9.12"
414
+ },
415
+ "toc": {
416
+ "base_numbering": 1,
417
+ "nav_menu": {},
418
+ "number_sections": true,
419
+ "sideBar": true,
420
+ "skip_h1_title": false,
421
+ "title_cell": "Table of Contents",
422
+ "title_sidebar": "Contents",
423
+ "toc_cell": false,
424
+ "toc_position": {
425
+ "height": "calc(100% - 180px)",
426
+ "left": "10px",
427
+ "top": "150px",
428
+ "width": "288px"
429
+ },
430
+ "toc_section_display": true,
431
+ "toc_window_display": true
432
+ }
433
+ },
434
+ "nbformat": 4,
435
+ "nbformat_minor": 2
436
+ }
04_python中的break与continue.ipynb ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "name": "stdout",
10
+ "output_type": "stream",
11
+ "text": [
12
+ "1\n",
13
+ "3\n",
14
+ "5\n",
15
+ "7\n",
16
+ "9\n"
17
+ ]
18
+ }
19
+ ],
20
+ "source": [
21
+ "for i in range(10):\n",
22
+ " if i % 2 == 0:\n",
23
+ " continue\n",
24
+ " \n",
25
+ " print(i)"
26
+ ]
27
+ },
28
+ {
29
+ "cell_type": "code",
30
+ "execution_count": 2,
31
+ "metadata": {},
32
+ "outputs": [
33
+ {
34
+ "name": "stdout",
35
+ "output_type": "stream",
36
+ "text": [
37
+ "Tom\n",
38
+ "Peter\n"
39
+ ]
40
+ }
41
+ ],
42
+ "source": [
43
+ "names = ['Tom', 'Peter', 'Jerry', 'Jack']\n",
44
+ "\n",
45
+ "for i in range(len(names)):\n",
46
+ " if i >=2:\n",
47
+ " break\n",
48
+ " print(names[i])"
49
+ ]
50
+ },
51
+ {
52
+ "cell_type": "code",
53
+ "execution_count": 3,
54
+ "metadata": {
55
+ "scrolled": true
56
+ },
57
+ "outputs": [
58
+ {
59
+ "name": "stdout",
60
+ "output_type": "stream",
61
+ "text": [
62
+ "1\n",
63
+ "3\n",
64
+ "5\n",
65
+ "7\n",
66
+ "9\n",
67
+ "1\n",
68
+ "3\n",
69
+ "5\n",
70
+ "7\n",
71
+ "9\n",
72
+ "1\n",
73
+ "3\n",
74
+ "5\n",
75
+ "7\n",
76
+ "9\n"
77
+ ]
78
+ }
79
+ ],
80
+ "source": [
81
+ "\n",
82
+ "for i in range(3):\n",
83
+ " for i in range(10):\n",
84
+ " if i % 2 == 0:\n",
85
+ " continue\n",
86
+ " print(i)"
87
+ ]
88
+ },
89
+ {
90
+ "cell_type": "code",
91
+ "execution_count": 4,
92
+ "metadata": {},
93
+ "outputs": [
94
+ {
95
+ "name": "stdout",
96
+ "output_type": "stream",
97
+ "text": [
98
+ "Tom\n",
99
+ "Peter\n",
100
+ "Tom\n",
101
+ "Peter\n",
102
+ "Tom\n",
103
+ "Peter\n"
104
+ ]
105
+ }
106
+ ],
107
+ "source": [
108
+ "names = ['Tom', 'Peter', 'Jerry', 'Jack']\n",
109
+ "\n",
110
+ "for i in range(3):\n",
111
+ " for i in range(len(names)):\n",
112
+ " if i >=2:\n",
113
+ " break\n",
114
+ " print(names[i])"
115
+ ]
116
+ }
117
+ ],
118
+ "metadata": {
119
+ "kernelspec": {
120
+ "display_name": "Python 3 (ipykernel)",
121
+ "language": "python",
122
+ "name": "python3"
123
+ },
124
+ "language_info": {
125
+ "codemirror_mode": {
126
+ "name": "ipython",
127
+ "version": 3
128
+ },
129
+ "file_extension": ".py",
130
+ "mimetype": "text/x-python",
131
+ "name": "python",
132
+ "nbconvert_exporter": "python",
133
+ "pygments_lexer": "ipython3",
134
+ "version": "3.9.12"
135
+ },
136
+ "toc": {
137
+ "base_numbering": 1,
138
+ "nav_menu": {},
139
+ "number_sections": true,
140
+ "sideBar": true,
141
+ "skip_h1_title": false,
142
+ "title_cell": "Table of Contents",
143
+ "title_sidebar": "Contents",
144
+ "toc_cell": false,
145
+ "toc_position": {
146
+ "height": "calc(100% - 180px)",
147
+ "left": "10px",
148
+ "top": "150px",
149
+ "width": "288px"
150
+ },
151
+ "toc_section_display": true,
152
+ "toc_window_display": true
153
+ }
154
+ },
155
+ "nbformat": 4,
156
+ "nbformat_minor": 2
157
+ }
Python_Pandas.ipynb ADDED
@@ -0,0 +1,864 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 33,
6
+ "metadata": {
7
+ "collapsed": true
8
+ },
9
+ "outputs": [],
10
+ "source": [
11
+ "import pandas as pd\n",
12
+ "import numpy as np"
13
+ ]
14
+ },
15
+ {
16
+ "cell_type": "code",
17
+ "execution_count": 3,
18
+ "metadata": {},
19
+ "outputs": [
20
+ {
21
+ "name": "stdout",
22
+ "output_type": "stream",
23
+ "text": [
24
+ "<class 'pandas.core.series.Series'>\n"
25
+ ]
26
+ }
27
+ ],
28
+ "source": [
29
+ "data = pd.Series([1,2,3,4,5])\n",
30
+ "print(type(data))"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "execution_count": 6,
36
+ "metadata": {},
37
+ "outputs": [
38
+ {
39
+ "data": {
40
+ "text/plain": [
41
+ "(numpy.ndarray, array([1, 2, 3, 4, 5], dtype=int64))"
42
+ ]
43
+ },
44
+ "execution_count": 6,
45
+ "metadata": {},
46
+ "output_type": "execute_result"
47
+ }
48
+ ],
49
+ "source": [
50
+ "type(data.values), data.values"
51
+ ]
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "execution_count": 7,
56
+ "metadata": {},
57
+ "outputs": [
58
+ {
59
+ "data": {
60
+ "text/plain": [
61
+ "(pandas.core.indexes.range.RangeIndex, RangeIndex(start=0, stop=5, step=1))"
62
+ ]
63
+ },
64
+ "execution_count": 7,
65
+ "metadata": {},
66
+ "output_type": "execute_result"
67
+ }
68
+ ],
69
+ "source": [
70
+ "type(data.index), data.index"
71
+ ]
72
+ },
73
+ {
74
+ "cell_type": "code",
75
+ "execution_count": 8,
76
+ "metadata": {},
77
+ "outputs": [
78
+ {
79
+ "data": {
80
+ "text/plain": [
81
+ "one 5\n",
82
+ "two 4\n",
83
+ "three 6\n",
84
+ "four 3\n",
85
+ "five 1\n",
86
+ "dtype: int64"
87
+ ]
88
+ },
89
+ "execution_count": 8,
90
+ "metadata": {},
91
+ "output_type": "execute_result"
92
+ }
93
+ ],
94
+ "source": [
95
+ "data=pd.Series([5,4,6,3,1],index=['one','two','three','four','five'])\n",
96
+ "data"
97
+ ]
98
+ },
99
+ {
100
+ "cell_type": "code",
101
+ "execution_count": 10,
102
+ "metadata": {},
103
+ "outputs": [
104
+ {
105
+ "data": {
106
+ "text/plain": [
107
+ "['a', 'b', 'c', 'd', 'e']"
108
+ ]
109
+ },
110
+ "execution_count": 10,
111
+ "metadata": {},
112
+ "output_type": "execute_result"
113
+ }
114
+ ],
115
+ "source": [
116
+ "list('abcde')"
117
+ ]
118
+ },
119
+ {
120
+ "cell_type": "code",
121
+ "execution_count": 11,
122
+ "metadata": {},
123
+ "outputs": [
124
+ {
125
+ "data": {
126
+ "text/plain": [
127
+ "bj 3000\n",
128
+ "gz 1500\n",
129
+ "sh 2800\n",
130
+ "sz 1200\n",
131
+ "dtype: int64"
132
+ ]
133
+ },
134
+ "execution_count": 11,
135
+ "metadata": {},
136
+ "output_type": "execute_result"
137
+ }
138
+ ],
139
+ "source": [
140
+ "population_dict={'bj':3000,'gz':1500,'sh':2800,'sz':1200}\n",
141
+ "population_series=pd.Series(population_dict)\n",
142
+ "population_series"
143
+ ]
144
+ },
145
+ {
146
+ "cell_type": "code",
147
+ "execution_count": 12,
148
+ "metadata": {},
149
+ "outputs": [
150
+ {
151
+ "data": {
152
+ "text/plain": [
153
+ "bj 3000\n",
154
+ "sh 2800\n",
155
+ "dtype: int64"
156
+ ]
157
+ },
158
+ "execution_count": 12,
159
+ "metadata": {},
160
+ "output_type": "execute_result"
161
+ }
162
+ ],
163
+ "source": [
164
+ "sub_series=pd.Series(population_dict,index=['bj','sh']) #如果存在取交集\n",
165
+ "sub_series"
166
+ ]
167
+ },
168
+ {
169
+ "cell_type": "code",
170
+ "execution_count": 13,
171
+ "metadata": {},
172
+ "outputs": [
173
+ {
174
+ "data": {
175
+ "text/plain": [
176
+ "bj 3000.0\n",
177
+ "xa NaN\n",
178
+ "dtype: float64"
179
+ ]
180
+ },
181
+ "execution_count": 13,
182
+ "metadata": {},
183
+ "output_type": "execute_result"
184
+ }
185
+ ],
186
+ "source": [
187
+ "sub_series=pd.Series(population_dict,index=['bj','xa']) #如果不存在则值为NaN\n",
188
+ "sub_series"
189
+ ]
190
+ },
191
+ {
192
+ "cell_type": "code",
193
+ "execution_count": 14,
194
+ "metadata": {},
195
+ "outputs": [
196
+ {
197
+ "data": {
198
+ "text/plain": [
199
+ "4 10\n",
200
+ "3 10\n",
201
+ "2 10\n",
202
+ "5 10\n",
203
+ "dtype: int64"
204
+ ]
205
+ },
206
+ "execution_count": 14,
207
+ "metadata": {},
208
+ "output_type": "execute_result"
209
+ }
210
+ ],
211
+ "source": [
212
+ "data=pd.Series(10,index=[4,3,2,5])\n",
213
+ "data"
214
+ ]
215
+ },
216
+ {
217
+ "cell_type": "code",
218
+ "execution_count": 17,
219
+ "metadata": {},
220
+ "outputs": [
221
+ {
222
+ "data": {
223
+ "text/html": [
224
+ "<div>\n",
225
+ "<style>\n",
226
+ " .dataframe thead tr:only-child th {\n",
227
+ " text-align: right;\n",
228
+ " }\n",
229
+ "\n",
230
+ " .dataframe thead th {\n",
231
+ " text-align: left;\n",
232
+ " }\n",
233
+ "\n",
234
+ " .dataframe tbody tr th {\n",
235
+ " vertical-align: top;\n",
236
+ " }\n",
237
+ "</style>\n",
238
+ "<table border=\"1\" class=\"dataframe\">\n",
239
+ " <thead>\n",
240
+ " <tr style=\"text-align: right;\">\n",
241
+ " <th></th>\n",
242
+ " <th>area</th>\n",
243
+ " <th>population</th>\n",
244
+ " </tr>\n",
245
+ " </thead>\n",
246
+ " <tbody>\n",
247
+ " <tr>\n",
248
+ " <th>beijing</th>\n",
249
+ " <td>300</td>\n",
250
+ " <td>3000</td>\n",
251
+ " </tr>\n",
252
+ " <tr>\n",
253
+ " <th>guangzhou</th>\n",
254
+ " <td>200</td>\n",
255
+ " <td>1800</td>\n",
256
+ " </tr>\n",
257
+ " <tr>\n",
258
+ " <th>shanghai</th>\n",
259
+ " <td>180</td>\n",
260
+ " <td>1200</td>\n",
261
+ " </tr>\n",
262
+ " </tbody>\n",
263
+ "</table>\n",
264
+ "</div>"
265
+ ],
266
+ "text/plain": [
267
+ " area population\n",
268
+ "beijing 300 3000\n",
269
+ "guangzhou 200 1800\n",
270
+ "shanghai 180 1200"
271
+ ]
272
+ },
273
+ "execution_count": 17,
274
+ "metadata": {},
275
+ "output_type": "execute_result"
276
+ }
277
+ ],
278
+ "source": [
279
+ "population_dict={'beijing':3000,'shanghai':1200,'guangzhou':1800}\n",
280
+ "area_dict={'beijing':300,'guangzhou':200,'shanghai':180}\n",
281
+ "population_series=pd.Series(population_dict)\n",
282
+ "area_series=pd.Series(area_dict)\n",
283
+ "citys=pd.DataFrame({'area':area_series,'population':population_series})\n",
284
+ "citys"
285
+ ]
286
+ },
287
+ {
288
+ "cell_type": "code",
289
+ "execution_count": 21,
290
+ "metadata": {},
291
+ "outputs": [
292
+ {
293
+ "data": {
294
+ "text/plain": [
295
+ "(numpy.ndarray, (3, 2), array([[ 300, 3000],\n",
296
+ " [ 200, 1800],\n",
297
+ " [ 180, 1200]], dtype=int64))"
298
+ ]
299
+ },
300
+ "execution_count": 21,
301
+ "metadata": {},
302
+ "output_type": "execute_result"
303
+ }
304
+ ],
305
+ "source": [
306
+ "type(citys.values) ,citys.values.shape, citys.values"
307
+ ]
308
+ },
309
+ {
310
+ "cell_type": "code",
311
+ "execution_count": 22,
312
+ "metadata": {},
313
+ "outputs": [
314
+ {
315
+ "data": {
316
+ "text/plain": [
317
+ "(pandas.core.indexes.base.Index,\n",
318
+ " Index(['beijing', 'guangzhou', 'shanghai'], dtype='object'))"
319
+ ]
320
+ },
321
+ "execution_count": 22,
322
+ "metadata": {},
323
+ "output_type": "execute_result"
324
+ }
325
+ ],
326
+ "source": [
327
+ "type(citys.index), citys.index"
328
+ ]
329
+ },
330
+ {
331
+ "cell_type": "code",
332
+ "execution_count": 23,
333
+ "metadata": {},
334
+ "outputs": [
335
+ {
336
+ "data": {
337
+ "text/plain": [
338
+ "(pandas.core.indexes.base.Index, Index(['area', 'population'], dtype='object'))"
339
+ ]
340
+ },
341
+ "execution_count": 23,
342
+ "metadata": {},
343
+ "output_type": "execute_result"
344
+ }
345
+ ],
346
+ "source": [
347
+ "type(citys.columns), citys.columns"
348
+ ]
349
+ },
350
+ {
351
+ "cell_type": "code",
352
+ "execution_count": 24,
353
+ "metadata": {},
354
+ "outputs": [
355
+ {
356
+ "data": {
357
+ "text/html": [
358
+ "<div>\n",
359
+ "<style>\n",
360
+ " .dataframe thead tr:only-child th {\n",
361
+ " text-align: right;\n",
362
+ " }\n",
363
+ "\n",
364
+ " .dataframe thead th {\n",
365
+ " text-align: left;\n",
366
+ " }\n",
367
+ "\n",
368
+ " .dataframe tbody tr th {\n",
369
+ " vertical-align: top;\n",
370
+ " }\n",
371
+ "</style>\n",
372
+ "<table border=\"1\" class=\"dataframe\">\n",
373
+ " <thead>\n",
374
+ " <tr style=\"text-align: right;\">\n",
375
+ " <th></th>\n",
376
+ " <th>beijing</th>\n",
377
+ " <th>guangzhou</th>\n",
378
+ " <th>shanghai</th>\n",
379
+ " </tr>\n",
380
+ " </thead>\n",
381
+ " <tbody>\n",
382
+ " <tr>\n",
383
+ " <th>0</th>\n",
384
+ " <td>3000</td>\n",
385
+ " <td>1800</td>\n",
386
+ " <td>1200</td>\n",
387
+ " </tr>\n",
388
+ " <tr>\n",
389
+ " <th>1</th>\n",
390
+ " <td>300</td>\n",
391
+ " <td>200</td>\n",
392
+ " <td>180</td>\n",
393
+ " </tr>\n",
394
+ " </tbody>\n",
395
+ "</table>\n",
396
+ "</div>"
397
+ ],
398
+ "text/plain": [
399
+ " beijing guangzhou shanghai\n",
400
+ "0 3000 1800 1200\n",
401
+ "1 300 200 180"
402
+ ]
403
+ },
404
+ "execution_count": 24,
405
+ "metadata": {},
406
+ "output_type": "execute_result"
407
+ }
408
+ ],
409
+ "source": [
410
+ "population_dict={'beijing':3000,'shanghai':1200,'guangzhou':1800}\n",
411
+ "area_dict={'beijing':300,'shanghai':180,'guangzhou':200}\n",
412
+ "data=pd.DataFrame([population_dict,area_dict])\n",
413
+ "data"
414
+ ]
415
+ },
416
+ {
417
+ "cell_type": "code",
418
+ "execution_count": 25,
419
+ "metadata": {},
420
+ "outputs": [
421
+ {
422
+ "data": {
423
+ "text/html": [
424
+ "<div>\n",
425
+ "<style>\n",
426
+ " .dataframe thead tr:only-child th {\n",
427
+ " text-align: right;\n",
428
+ " }\n",
429
+ "\n",
430
+ " .dataframe thead th {\n",
431
+ " text-align: left;\n",
432
+ " }\n",
433
+ "\n",
434
+ " .dataframe tbody tr th {\n",
435
+ " vertical-align: top;\n",
436
+ " }\n",
437
+ "</style>\n",
438
+ "<table border=\"1\" class=\"dataframe\">\n",
439
+ " <thead>\n",
440
+ " <tr style=\"text-align: right;\">\n",
441
+ " <th></th>\n",
442
+ " <th>beijing</th>\n",
443
+ " <th>guangzhou</th>\n",
444
+ " <th>shanghai</th>\n",
445
+ " </tr>\n",
446
+ " </thead>\n",
447
+ " <tbody>\n",
448
+ " <tr>\n",
449
+ " <th>population</th>\n",
450
+ " <td>3000</td>\n",
451
+ " <td>1800</td>\n",
452
+ " <td>1200</td>\n",
453
+ " </tr>\n",
454
+ " <tr>\n",
455
+ " <th>area</th>\n",
456
+ " <td>300</td>\n",
457
+ " <td>200</td>\n",
458
+ " <td>180</td>\n",
459
+ " </tr>\n",
460
+ " </tbody>\n",
461
+ "</table>\n",
462
+ "</div>"
463
+ ],
464
+ "text/plain": [
465
+ " beijing guangzhou shanghai\n",
466
+ "population 3000 1800 1200\n",
467
+ "area 300 200 180"
468
+ ]
469
+ },
470
+ "execution_count": 25,
471
+ "metadata": {},
472
+ "output_type": "execute_result"
473
+ }
474
+ ],
475
+ "source": [
476
+ "population_dict={'beijing':3000,'shanghai':1200,'guangzhou':1800}\n",
477
+ "area_dict={'beijing':300,'shanghai':180,'guangzhou':200}\n",
478
+ "data=pd.DataFrame([population_dict,area_dict], index=['population','area'])\n",
479
+ "data"
480
+ ]
481
+ },
482
+ {
483
+ "cell_type": "code",
484
+ "execution_count": 28,
485
+ "metadata": {},
486
+ "outputs": [
487
+ {
488
+ "data": {
489
+ "text/html": [
490
+ "<div>\n",
491
+ "<style>\n",
492
+ " .dataframe thead tr:only-child th {\n",
493
+ " text-align: right;\n",
494
+ " }\n",
495
+ "\n",
496
+ " .dataframe thead th {\n",
497
+ " text-align: left;\n",
498
+ " }\n",
499
+ "\n",
500
+ " .dataframe tbody tr th {\n",
501
+ " vertical-align: top;\n",
502
+ " }\n",
503
+ "</style>\n",
504
+ "<table border=\"1\" class=\"dataframe\">\n",
505
+ " <thead>\n",
506
+ " <tr style=\"text-align: right;\">\n",
507
+ " <th></th>\n",
508
+ " <th>population</th>\n",
509
+ " </tr>\n",
510
+ " </thead>\n",
511
+ " <tbody>\n",
512
+ " <tr>\n",
513
+ " <th>beijing</th>\n",
514
+ " <td>3000</td>\n",
515
+ " </tr>\n",
516
+ " <tr>\n",
517
+ " <th>guangzhou</th>\n",
518
+ " <td>1800</td>\n",
519
+ " </tr>\n",
520
+ " <tr>\n",
521
+ " <th>shanghai</th>\n",
522
+ " <td>1200</td>\n",
523
+ " </tr>\n",
524
+ " </tbody>\n",
525
+ "</table>\n",
526
+ "</div>"
527
+ ],
528
+ "text/plain": [
529
+ " population\n",
530
+ "beijing 3000\n",
531
+ "guangzhou 1800\n",
532
+ "shanghai 1200"
533
+ ]
534
+ },
535
+ "execution_count": 28,
536
+ "metadata": {},
537
+ "output_type": "execute_result"
538
+ }
539
+ ],
540
+ "source": [
541
+ "population_series=pd.Series(population_dict)\n",
542
+ "# pd.DataFrame(population_series,columns=['population'])\n",
543
+ "pd.DataFrame({'population':population_series})"
544
+ ]
545
+ },
546
+ {
547
+ "cell_type": "code",
548
+ "execution_count": 32,
549
+ "metadata": {},
550
+ "outputs": [
551
+ {
552
+ "data": {
553
+ "text/html": [
554
+ "<div>\n",
555
+ "<style>\n",
556
+ " .dataframe thead tr:only-child th {\n",
557
+ " text-align: right;\n",
558
+ " }\n",
559
+ "\n",
560
+ " .dataframe thead th {\n",
561
+ " text-align: left;\n",
562
+ " }\n",
563
+ "\n",
564
+ " .dataframe tbody tr th {\n",
565
+ " vertical-align: top;\n",
566
+ " }\n",
567
+ "</style>\n",
568
+ "<table border=\"1\" class=\"dataframe\">\n",
569
+ " <thead>\n",
570
+ " <tr style=\"text-align: right;\">\n",
571
+ " <th></th>\n",
572
+ " <th>a</th>\n",
573
+ " <th>b</th>\n",
574
+ " </tr>\n",
575
+ " </thead>\n",
576
+ " <tbody>\n",
577
+ " <tr>\n",
578
+ " <th>一</th>\n",
579
+ " <td>0</td>\n",
580
+ " <td>0</td>\n",
581
+ " </tr>\n",
582
+ " <tr>\n",
583
+ " <th>二</th>\n",
584
+ " <td>1</td>\n",
585
+ " <td>2</td>\n",
586
+ " </tr>\n",
587
+ " <tr>\n",
588
+ " <th>三</th>\n",
589
+ " <td>2</td>\n",
590
+ " <td>4</td>\n",
591
+ " </tr>\n",
592
+ " </tbody>\n",
593
+ "</table>\n",
594
+ "</div>"
595
+ ],
596
+ "text/plain": [
597
+ " a b\n",
598
+ "一 0 0\n",
599
+ "二 1 2\n",
600
+ "三 2 4"
601
+ ]
602
+ },
603
+ "execution_count": 32,
604
+ "metadata": {},
605
+ "output_type": "execute_result"
606
+ }
607
+ ],
608
+ "source": [
609
+ "pd.DataFrame([{'a':i,'b':i*2} for i in range(3)], index=['一','二','三'])"
610
+ ]
611
+ },
612
+ {
613
+ "cell_type": "code",
614
+ "execution_count": 37,
615
+ "metadata": {},
616
+ "outputs": [
617
+ {
618
+ "data": {
619
+ "text/html": [
620
+ "<div>\n",
621
+ "<style>\n",
622
+ " .dataframe thead tr:only-child th {\n",
623
+ " text-align: right;\n",
624
+ " }\n",
625
+ "\n",
626
+ " .dataframe thead th {\n",
627
+ " text-align: left;\n",
628
+ " }\n",
629
+ "\n",
630
+ " .dataframe tbody tr th {\n",
631
+ " vertical-align: top;\n",
632
+ " }\n",
633
+ "</style>\n",
634
+ "<table border=\"1\" class=\"dataframe\">\n",
635
+ " <thead>\n",
636
+ " <tr style=\"text-align: right;\">\n",
637
+ " <th></th>\n",
638
+ " <th>a</th>\n",
639
+ " <th>b</th>\n",
640
+ " <th>c</th>\n",
641
+ " </tr>\n",
642
+ " </thead>\n",
643
+ " <tbody>\n",
644
+ " <tr>\n",
645
+ " <th>a</th>\n",
646
+ " <td>88</td>\n",
647
+ " <td>59</td>\n",
648
+ " <td>18</td>\n",
649
+ " </tr>\n",
650
+ " <tr>\n",
651
+ " <th>b</th>\n",
652
+ " <td>35</td>\n",
653
+ " <td>95</td>\n",
654
+ " <td>79</td>\n",
655
+ " </tr>\n",
656
+ " <tr>\n",
657
+ " <th>c</th>\n",
658
+ " <td>18</td>\n",
659
+ " <td>26</td>\n",
660
+ " <td>18</td>\n",
661
+ " </tr>\n",
662
+ " <tr>\n",
663
+ " <th>d</th>\n",
664
+ " <td>12</td>\n",
665
+ " <td>70</td>\n",
666
+ " <td>63</td>\n",
667
+ " </tr>\n",
668
+ " </tbody>\n",
669
+ "</table>\n",
670
+ "</div>"
671
+ ],
672
+ "text/plain": [
673
+ " a b c\n",
674
+ "a 88 59 18\n",
675
+ "b 35 95 79\n",
676
+ "c 18 26 18\n",
677
+ "d 12 70 63"
678
+ ]
679
+ },
680
+ "execution_count": 37,
681
+ "metadata": {},
682
+ "output_type": "execute_result"
683
+ }
684
+ ],
685
+ "source": [
686
+ "pd.DataFrame(np.random.randint(0, 100, (4,3)), index=['a','b','c','d'], columns=['a','b','c'])"
687
+ ]
688
+ },
689
+ {
690
+ "cell_type": "code",
691
+ "execution_count": 38,
692
+ "metadata": {},
693
+ "outputs": [
694
+ {
695
+ "data": {
696
+ "text/plain": [
697
+ "'根据key获取:'"
698
+ ]
699
+ },
700
+ "metadata": {},
701
+ "output_type": "display_data"
702
+ },
703
+ {
704
+ "data": {
705
+ "text/plain": [
706
+ "4"
707
+ ]
708
+ },
709
+ "metadata": {},
710
+ "output_type": "display_data"
711
+ },
712
+ {
713
+ "data": {
714
+ "text/plain": [
715
+ "'切片获取:'"
716
+ ]
717
+ },
718
+ "metadata": {},
719
+ "output_type": "display_data"
720
+ },
721
+ {
722
+ "data": {
723
+ "text/plain": [
724
+ "a 4\n",
725
+ "b 3\n",
726
+ "c 25\n",
727
+ "d 2\n",
728
+ "dtype: int64"
729
+ ]
730
+ },
731
+ "metadata": {},
732
+ "output_type": "display_data"
733
+ },
734
+ {
735
+ "data": {
736
+ "text/plain": [
737
+ "'索引获取:'"
738
+ ]
739
+ },
740
+ "metadata": {},
741
+ "output_type": "display_data"
742
+ },
743
+ {
744
+ "data": {
745
+ "text/plain": [
746
+ "3"
747
+ ]
748
+ },
749
+ "metadata": {},
750
+ "output_type": "display_data"
751
+ },
752
+ {
753
+ "data": {
754
+ "text/plain": [
755
+ "'索引切片:'"
756
+ ]
757
+ },
758
+ "metadata": {},
759
+ "output_type": "display_data"
760
+ },
761
+ {
762
+ "data": {
763
+ "text/plain": [
764
+ "c 25\n",
765
+ "d 2\n",
766
+ "dtype: int64"
767
+ ]
768
+ },
769
+ "metadata": {},
770
+ "output_type": "display_data"
771
+ }
772
+ ],
773
+ "source": [
774
+ "data=pd.Series([4,3,25,2,3],index=list('abcde'))\n",
775
+ "display('根据key获取:',data['a'])\n",
776
+ "display('切片获取:',data['a':'d'])\n",
777
+ "display('索引获取:',data[1])\n",
778
+ "display('索引切片:',data[2:4])"
779
+ ]
780
+ },
781
+ {
782
+ "cell_type": "code",
783
+ "execution_count": 39,
784
+ "metadata": {},
785
+ "outputs": [
786
+ {
787
+ "data": {
788
+ "text/plain": [
789
+ "5"
790
+ ]
791
+ },
792
+ "execution_count": 39,
793
+ "metadata": {},
794
+ "output_type": "execute_result"
795
+ }
796
+ ],
797
+ "source": [
798
+ "data=pd.Series([5,6,7,8],index=[1,2,3,4])\n",
799
+ "data[1] "
800
+ ]
801
+ },
802
+ {
803
+ "cell_type": "code",
804
+ "execution_count": 40,
805
+ "metadata": {},
806
+ "outputs": [
807
+ {
808
+ "data": {
809
+ "text/plain": [
810
+ "5"
811
+ ]
812
+ },
813
+ "execution_count": 40,
814
+ "metadata": {},
815
+ "output_type": "execute_result"
816
+ }
817
+ ],
818
+ "source": [
819
+ "data.loc[1]"
820
+ ]
821
+ },
822
+ {
823
+ "cell_type": "code",
824
+ "execution_count": 41,
825
+ "metadata": {},
826
+ "outputs": [
827
+ {
828
+ "data": {
829
+ "text/plain": [
830
+ "6"
831
+ ]
832
+ },
833
+ "execution_count": 41,
834
+ "metadata": {},
835
+ "output_type": "execute_result"
836
+ }
837
+ ],
838
+ "source": [
839
+ "data.iloc[1]"
840
+ ]
841
+ }
842
+ ],
843
+ "metadata": {
844
+ "kernelspec": {
845
+ "display_name": "Python 3",
846
+ "language": "python",
847
+ "name": "python3"
848
+ },
849
+ "language_info": {
850
+ "codemirror_mode": {
851
+ "name": "ipython",
852
+ "version": 3
853
+ },
854
+ "file_extension": ".py",
855
+ "mimetype": "text/x-python",
856
+ "name": "python",
857
+ "nbconvert_exporter": "python",
858
+ "pygments_lexer": "ipython3",
859
+ "version": "3.6.3"
860
+ }
861
+ },
862
+ "nbformat": 4,
863
+ "nbformat_minor": 2
864
+ }
Python_Pandas_DataFrame.ipynb ADDED
@@ -0,0 +1,514 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {
7
+ "collapsed": true
8
+ },
9
+ "outputs": [],
10
+ "source": [
11
+ "import pandas as pd\n",
12
+ "import numpy as np"
13
+ ]
14
+ },
15
+ {
16
+ "cell_type": "code",
17
+ "execution_count": 3,
18
+ "metadata": {},
19
+ "outputs": [
20
+ {
21
+ "data": {
22
+ "text/html": [
23
+ "<div>\n",
24
+ "<style>\n",
25
+ " .dataframe thead tr:only-child th {\n",
26
+ " text-align: right;\n",
27
+ " }\n",
28
+ "\n",
29
+ " .dataframe thead th {\n",
30
+ " text-align: left;\n",
31
+ " }\n",
32
+ "\n",
33
+ " .dataframe tbody tr th {\n",
34
+ " vertical-align: top;\n",
35
+ " }\n",
36
+ "</style>\n",
37
+ "<table border=\"1\" class=\"dataframe\">\n",
38
+ " <thead>\n",
39
+ " <tr style=\"text-align: right;\">\n",
40
+ " <th></th>\n",
41
+ " <th>A</th>\n",
42
+ " <th>B</th>\n",
43
+ " <th>C</th>\n",
44
+ " <th>D</th>\n",
45
+ " </tr>\n",
46
+ " </thead>\n",
47
+ " <tbody>\n",
48
+ " <tr>\n",
49
+ " <th>a</th>\n",
50
+ " <td>0</td>\n",
51
+ " <td>1</td>\n",
52
+ " <td>2</td>\n",
53
+ " <td>3</td>\n",
54
+ " </tr>\n",
55
+ " <tr>\n",
56
+ " <th>b</th>\n",
57
+ " <td>4</td>\n",
58
+ " <td>5</td>\n",
59
+ " <td>6</td>\n",
60
+ " <td>7</td>\n",
61
+ " </tr>\n",
62
+ " <tr>\n",
63
+ " <th>c</th>\n",
64
+ " <td>8</td>\n",
65
+ " <td>9</td>\n",
66
+ " <td>10</td>\n",
67
+ " <td>11</td>\n",
68
+ " </tr>\n",
69
+ " </tbody>\n",
70
+ "</table>\n",
71
+ "</div>"
72
+ ],
73
+ "text/plain": [
74
+ " A B C D\n",
75
+ "a 0 1 2 3\n",
76
+ "b 4 5 6 7\n",
77
+ "c 8 9 10 11"
78
+ ]
79
+ },
80
+ "execution_count": 3,
81
+ "metadata": {},
82
+ "output_type": "execute_result"
83
+ }
84
+ ],
85
+ "source": [
86
+ "data=pd.DataFrame(np.arange(12).reshape(3,4),index=list('abc'),columns=list('ABCD'))\n",
87
+ "data"
88
+ ]
89
+ },
90
+ {
91
+ "cell_type": "code",
92
+ "execution_count": 5,
93
+ "metadata": {},
94
+ "outputs": [
95
+ {
96
+ "data": {
97
+ "text/plain": [
98
+ "(a 1\n",
99
+ " b 5\n",
100
+ " c 9\n",
101
+ " Name: B, dtype: int32, pandas.core.series.Series)"
102
+ ]
103
+ },
104
+ "execution_count": 5,
105
+ "metadata": {},
106
+ "output_type": "execute_result"
107
+ }
108
+ ],
109
+ "source": [
110
+ "data['B'], type(data['B'])"
111
+ ]
112
+ },
113
+ {
114
+ "cell_type": "code",
115
+ "execution_count": 7,
116
+ "metadata": {},
117
+ "outputs": [
118
+ {
119
+ "data": {
120
+ "text/plain": [
121
+ "( A B\n",
122
+ " a 0 1\n",
123
+ " b 4 5\n",
124
+ " c 8 9, pandas.core.frame.DataFrame)"
125
+ ]
126
+ },
127
+ "execution_count": 7,
128
+ "metadata": {},
129
+ "output_type": "execute_result"
130
+ }
131
+ ],
132
+ "source": [
133
+ "data[['A','B']], type(data[['A','B']])"
134
+ ]
135
+ },
136
+ {
137
+ "cell_type": "code",
138
+ "execution_count": 8,
139
+ "metadata": {},
140
+ "outputs": [
141
+ {
142
+ "data": {
143
+ "text/plain": [
144
+ "a 0\n",
145
+ "b 4\n",
146
+ "c 8\n",
147
+ "Name: A, dtype: int32"
148
+ ]
149
+ },
150
+ "execution_count": 8,
151
+ "metadata": {},
152
+ "output_type": "execute_result"
153
+ }
154
+ ],
155
+ "source": [
156
+ "data.iloc[:,0]"
157
+ ]
158
+ },
159
+ {
160
+ "cell_type": "code",
161
+ "execution_count": 11,
162
+ "metadata": {},
163
+ "outputs": [
164
+ {
165
+ "data": {
166
+ "text/html": [
167
+ "<div>\n",
168
+ "<style>\n",
169
+ " .dataframe thead tr:only-child th {\n",
170
+ " text-align: right;\n",
171
+ " }\n",
172
+ "\n",
173
+ " .dataframe thead th {\n",
174
+ " text-align: left;\n",
175
+ " }\n",
176
+ "\n",
177
+ " .dataframe tbody tr th {\n",
178
+ " vertical-align: top;\n",
179
+ " }\n",
180
+ "</style>\n",
181
+ "<table border=\"1\" class=\"dataframe\">\n",
182
+ " <thead>\n",
183
+ " <tr style=\"text-align: right;\">\n",
184
+ " <th></th>\n",
185
+ " <th>A</th>\n",
186
+ " <th>C</th>\n",
187
+ " </tr>\n",
188
+ " </thead>\n",
189
+ " <tbody>\n",
190
+ " <tr>\n",
191
+ " <th>a</th>\n",
192
+ " <td>0</td>\n",
193
+ " <td>2</td>\n",
194
+ " </tr>\n",
195
+ " <tr>\n",
196
+ " <th>b</th>\n",
197
+ " <td>4</td>\n",
198
+ " <td>6</td>\n",
199
+ " </tr>\n",
200
+ " <tr>\n",
201
+ " <th>c</th>\n",
202
+ " <td>8</td>\n",
203
+ " <td>10</td>\n",
204
+ " </tr>\n",
205
+ " </tbody>\n",
206
+ "</table>\n",
207
+ "</div>"
208
+ ],
209
+ "text/plain": [
210
+ " A C\n",
211
+ "a 0 2\n",
212
+ "b 4 6\n",
213
+ "c 8 10"
214
+ ]
215
+ },
216
+ "execution_count": 11,
217
+ "metadata": {},
218
+ "output_type": "execute_result"
219
+ }
220
+ ],
221
+ "source": [
222
+ "data.iloc[:,[0,2]]"
223
+ ]
224
+ },
225
+ {
226
+ "cell_type": "code",
227
+ "execution_count": 12,
228
+ "metadata": {},
229
+ "outputs": [
230
+ {
231
+ "data": {
232
+ "text/html": [
233
+ "<div>\n",
234
+ "<style>\n",
235
+ " .dataframe thead tr:only-child th {\n",
236
+ " text-align: right;\n",
237
+ " }\n",
238
+ "\n",
239
+ " .dataframe thead th {\n",
240
+ " text-align: left;\n",
241
+ " }\n",
242
+ "\n",
243
+ " .dataframe tbody tr th {\n",
244
+ " vertical-align: top;\n",
245
+ " }\n",
246
+ "</style>\n",
247
+ "<table border=\"1\" class=\"dataframe\">\n",
248
+ " <thead>\n",
249
+ " <tr style=\"text-align: right;\">\n",
250
+ " <th></th>\n",
251
+ " <th>A</th>\n",
252
+ " <th>B</th>\n",
253
+ " </tr>\n",
254
+ " </thead>\n",
255
+ " <tbody>\n",
256
+ " <tr>\n",
257
+ " <th>a</th>\n",
258
+ " <td>0</td>\n",
259
+ " <td>1</td>\n",
260
+ " </tr>\n",
261
+ " <tr>\n",
262
+ " <th>b</th>\n",
263
+ " <td>4</td>\n",
264
+ " <td>5</td>\n",
265
+ " </tr>\n",
266
+ " <tr>\n",
267
+ " <th>c</th>\n",
268
+ " <td>8</td>\n",
269
+ " <td>9</td>\n",
270
+ " </tr>\n",
271
+ " </tbody>\n",
272
+ "</table>\n",
273
+ "</div>"
274
+ ],
275
+ "text/plain": [
276
+ " A B\n",
277
+ "a 0 1\n",
278
+ "b 4 5\n",
279
+ "c 8 9"
280
+ ]
281
+ },
282
+ "execution_count": 12,
283
+ "metadata": {},
284
+ "output_type": "execute_result"
285
+ }
286
+ ],
287
+ "source": [
288
+ "data.iloc[:,0:2]"
289
+ ]
290
+ },
291
+ {
292
+ "cell_type": "code",
293
+ "execution_count": 13,
294
+ "metadata": {},
295
+ "outputs": [
296
+ {
297
+ "data": {
298
+ "text/html": [
299
+ "<div>\n",
300
+ "<style>\n",
301
+ " .dataframe thead tr:only-child th {\n",
302
+ " text-align: right;\n",
303
+ " }\n",
304
+ "\n",
305
+ " .dataframe thead th {\n",
306
+ " text-align: left;\n",
307
+ " }\n",
308
+ "\n",
309
+ " .dataframe tbody tr th {\n",
310
+ " vertical-align: top;\n",
311
+ " }\n",
312
+ "</style>\n",
313
+ "<table border=\"1\" class=\"dataframe\">\n",
314
+ " <thead>\n",
315
+ " <tr style=\"text-align: right;\">\n",
316
+ " <th></th>\n",
317
+ " <th>A</th>\n",
318
+ " <th>B</th>\n",
319
+ " <th>C</th>\n",
320
+ " </tr>\n",
321
+ " </thead>\n",
322
+ " <tbody>\n",
323
+ " <tr>\n",
324
+ " <th>a</th>\n",
325
+ " <td>0</td>\n",
326
+ " <td>1</td>\n",
327
+ " <td>2</td>\n",
328
+ " </tr>\n",
329
+ " <tr>\n",
330
+ " <th>b</th>\n",
331
+ " <td>4</td>\n",
332
+ " <td>5</td>\n",
333
+ " <td>6</td>\n",
334
+ " </tr>\n",
335
+ " <tr>\n",
336
+ " <th>c</th>\n",
337
+ " <td>8</td>\n",
338
+ " <td>9</td>\n",
339
+ " <td>10</td>\n",
340
+ " </tr>\n",
341
+ " </tbody>\n",
342
+ "</table>\n",
343
+ "</div>"
344
+ ],
345
+ "text/plain": [
346
+ " A B C\n",
347
+ "a 0 1 2\n",
348
+ "b 4 5 6\n",
349
+ "c 8 9 10"
350
+ ]
351
+ },
352
+ "execution_count": 13,
353
+ "metadata": {},
354
+ "output_type": "execute_result"
355
+ }
356
+ ],
357
+ "source": [
358
+ "data.loc[:, 'A':'C']"
359
+ ]
360
+ },
361
+ {
362
+ "cell_type": "code",
363
+ "execution_count": 14,
364
+ "metadata": {},
365
+ "outputs": [
366
+ {
367
+ "data": {
368
+ "text/html": [
369
+ "<div>\n",
370
+ "<style>\n",
371
+ " .dataframe thead tr:only-child th {\n",
372
+ " text-align: right;\n",
373
+ " }\n",
374
+ "\n",
375
+ " .dataframe thead th {\n",
376
+ " text-align: left;\n",
377
+ " }\n",
378
+ "\n",
379
+ " .dataframe tbody tr th {\n",
380
+ " vertical-align: top;\n",
381
+ " }\n",
382
+ "</style>\n",
383
+ "<table border=\"1\" class=\"dataframe\">\n",
384
+ " <thead>\n",
385
+ " <tr style=\"text-align: right;\">\n",
386
+ " <th></th>\n",
387
+ " <th>A</th>\n",
388
+ " <th>B</th>\n",
389
+ " </tr>\n",
390
+ " </thead>\n",
391
+ " <tbody>\n",
392
+ " <tr>\n",
393
+ " <th>a</th>\n",
394
+ " <td>0</td>\n",
395
+ " <td>1</td>\n",
396
+ " </tr>\n",
397
+ " <tr>\n",
398
+ " <th>b</th>\n",
399
+ " <td>4</td>\n",
400
+ " <td>5</td>\n",
401
+ " </tr>\n",
402
+ " </tbody>\n",
403
+ "</table>\n",
404
+ "</div>"
405
+ ],
406
+ "text/plain": [
407
+ " A B\n",
408
+ "a 0 1\n",
409
+ "b 4 5"
410
+ ]
411
+ },
412
+ "execution_count": 14,
413
+ "metadata": {},
414
+ "output_type": "execute_result"
415
+ }
416
+ ],
417
+ "source": [
418
+ "data.loc['a':'b','A':'B']"
419
+ ]
420
+ },
421
+ {
422
+ "cell_type": "code",
423
+ "execution_count": 15,
424
+ "metadata": {},
425
+ "outputs": [
426
+ {
427
+ "data": {
428
+ "text/html": [
429
+ "<div>\n",
430
+ "<style>\n",
431
+ " .dataframe thead tr:only-child th {\n",
432
+ " text-align: right;\n",
433
+ " }\n",
434
+ "\n",
435
+ " .dataframe thead th {\n",
436
+ " text-align: left;\n",
437
+ " }\n",
438
+ "\n",
439
+ " .dataframe tbody tr th {\n",
440
+ " vertical-align: top;\n",
441
+ " }\n",
442
+ "</style>\n",
443
+ "<table border=\"1\" class=\"dataframe\">\n",
444
+ " <thead>\n",
445
+ " <tr style=\"text-align: right;\">\n",
446
+ " <th></th>\n",
447
+ " <th>A</th>\n",
448
+ " <th>B</th>\n",
449
+ " </tr>\n",
450
+ " </thead>\n",
451
+ " <tbody>\n",
452
+ " <tr>\n",
453
+ " <th>a</th>\n",
454
+ " <td>0</td>\n",
455
+ " <td>1</td>\n",
456
+ " </tr>\n",
457
+ " <tr>\n",
458
+ " <th>b</th>\n",
459
+ " <td>4</td>\n",
460
+ " <td>5</td>\n",
461
+ " </tr>\n",
462
+ " </tbody>\n",
463
+ "</table>\n",
464
+ "</div>"
465
+ ],
466
+ "text/plain": [
467
+ " A B\n",
468
+ "a 0 1\n",
469
+ "b 4 5"
470
+ ]
471
+ },
472
+ "execution_count": 15,
473
+ "metadata": {},
474
+ "output_type": "execute_result"
475
+ }
476
+ ],
477
+ "source": [
478
+ "data.iloc[0:2, 0:2]"
479
+ ]
480
+ },
481
+ {
482
+ "cell_type": "code",
483
+ "execution_count": null,
484
+ "metadata": {
485
+ "collapsed": true
486
+ },
487
+ "outputs": [],
488
+ "source": [
489
+ "print(data.loc[['a','c'],['A','B','D']])"
490
+ ]
491
+ }
492
+ ],
493
+ "metadata": {
494
+ "kernelspec": {
495
+ "display_name": "Python 3",
496
+ "language": "python",
497
+ "name": "python3"
498
+ },
499
+ "language_info": {
500
+ "codemirror_mode": {
501
+ "name": "ipython",
502
+ "version": 3
503
+ },
504
+ "file_extension": ".py",
505
+ "mimetype": "text/x-python",
506
+ "name": "python",
507
+ "nbconvert_exporter": "python",
508
+ "pygments_lexer": "ipython3",
509
+ "version": "3.6.3"
510
+ }
511
+ },
512
+ "nbformat": 4,
513
+ "nbformat_minor": 2
514
+ }
Python_Pandas_方法.ipynb ADDED
@@ -0,0 +1,2781 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 23,
6
+ "metadata": {
7
+ "collapsed": true
8
+ },
9
+ "outputs": [],
10
+ "source": [
11
+ "import pandas as pd\n",
12
+ "import numpy as np"
13
+ ]
14
+ },
15
+ {
16
+ "cell_type": "code",
17
+ "execution_count": 3,
18
+ "metadata": {},
19
+ "outputs": [
20
+ {
21
+ "data": {
22
+ "text/html": [
23
+ "<div>\n",
24
+ "<style>\n",
25
+ " .dataframe thead tr:only-child th {\n",
26
+ " text-align: right;\n",
27
+ " }\n",
28
+ "\n",
29
+ " .dataframe thead th {\n",
30
+ " text-align: left;\n",
31
+ " }\n",
32
+ "\n",
33
+ " .dataframe tbody tr th {\n",
34
+ " vertical-align: top;\n",
35
+ " }\n",
36
+ "</style>\n",
37
+ "<table border=\"1\" class=\"dataframe\">\n",
38
+ " <thead>\n",
39
+ " <tr style=\"text-align: right;\">\n",
40
+ " <th></th>\n",
41
+ " <th>Sno</th>\n",
42
+ " <th>Sex</th>\n",
43
+ " <th>Age</th>\n",
44
+ " <th>Score</th>\n",
45
+ " </tr>\n",
46
+ " </thead>\n",
47
+ " <tbody>\n",
48
+ " <tr>\n",
49
+ " <th>zs</th>\n",
50
+ " <td>1001</td>\n",
51
+ " <td>man</td>\n",
52
+ " <td>17</td>\n",
53
+ " <td>80</td>\n",
54
+ " </tr>\n",
55
+ " <tr>\n",
56
+ " <th>lisi</th>\n",
57
+ " <td>1002</td>\n",
58
+ " <td>woman</td>\n",
59
+ " <td>18</td>\n",
60
+ " <td>97</td>\n",
61
+ " </tr>\n",
62
+ " <tr>\n",
63
+ " <th>ww</th>\n",
64
+ " <td>1003</td>\n",
65
+ " <td>man</td>\n",
66
+ " <td>19</td>\n",
67
+ " <td>95</td>\n",
68
+ " </tr>\n",
69
+ " </tbody>\n",
70
+ "</table>\n",
71
+ "</div>"
72
+ ],
73
+ "text/plain": [
74
+ " Sno Sex Age Score\n",
75
+ "zs 1001 man 17 80\n",
76
+ "lisi 1002 woman 18 97\n",
77
+ "ww 1003 man 19 95"
78
+ ]
79
+ },
80
+ "execution_count": 3,
81
+ "metadata": {},
82
+ "output_type": "execute_result"
83
+ }
84
+ ],
85
+ "source": [
86
+ "data = pd.DataFrame({\n",
87
+ " 'Name':['zs','lisi','ww'],\n",
88
+ " 'Sno':['1001','1002','1003'],\n",
89
+ " 'Sex':['man','woman','man'],\n",
90
+ " 'Age':[17,18,19],\n",
91
+ " 'Score':[80,97,95]\n",
92
+ "},columns=['Sno','Sex','Age','Score'],index=['zs','lisi','ww'])\n",
93
+ "data"
94
+ ]
95
+ },
96
+ {
97
+ "cell_type": "code",
98
+ "execution_count": 6,
99
+ "metadata": {},
100
+ "outputs": [
101
+ {
102
+ "data": {
103
+ "text/plain": [
104
+ "(18.0, 17, 19, 1.0)"
105
+ ]
106
+ },
107
+ "execution_count": 6,
108
+ "metadata": {},
109
+ "output_type": "execute_result"
110
+ }
111
+ ],
112
+ "source": [
113
+ "ages = data['Age']\n",
114
+ "ages.mean(), ages.min(), ages.max(), ages.std()"
115
+ ]
116
+ },
117
+ {
118
+ "cell_type": "code",
119
+ "execution_count": 8,
120
+ "metadata": {},
121
+ "outputs": [
122
+ {
123
+ "data": {
124
+ "text/plain": [
125
+ "ww 19\n",
126
+ "lisi 18\n",
127
+ "zs 17\n",
128
+ "Name: Age, dtype: int64"
129
+ ]
130
+ },
131
+ "execution_count": 8,
132
+ "metadata": {},
133
+ "output_type": "execute_result"
134
+ }
135
+ ],
136
+ "source": [
137
+ "ages.sort_values(ascending=False)"
138
+ ]
139
+ },
140
+ {
141
+ "cell_type": "code",
142
+ "execution_count": 10,
143
+ "metadata": {},
144
+ "outputs": [
145
+ {
146
+ "name": "stdout",
147
+ "output_type": "stream",
148
+ "text": [
149
+ "90.66666666666667\n"
150
+ ]
151
+ },
152
+ {
153
+ "data": {
154
+ "text/plain": [
155
+ "lisi 97\n",
156
+ "ww 95\n",
157
+ "Name: Score, dtype: int64"
158
+ ]
159
+ },
160
+ "execution_count": 10,
161
+ "metadata": {},
162
+ "output_type": "execute_result"
163
+ }
164
+ ],
165
+ "source": [
166
+ "scores = data['Score']\n",
167
+ "print(scores.mean())\n",
168
+ "scores[scores>scores.mean()]"
169
+ ]
170
+ },
171
+ {
172
+ "cell_type": "code",
173
+ "execution_count": 19,
174
+ "metadata": {},
175
+ "outputs": [
176
+ {
177
+ "data": {
178
+ "text/html": [
179
+ "<div>\n",
180
+ "<style>\n",
181
+ " .dataframe thead tr:only-child th {\n",
182
+ " text-align: right;\n",
183
+ " }\n",
184
+ "\n",
185
+ " .dataframe thead th {\n",
186
+ " text-align: left;\n",
187
+ " }\n",
188
+ "\n",
189
+ " .dataframe tbody tr th {\n",
190
+ " vertical-align: top;\n",
191
+ " }\n",
192
+ "</style>\n",
193
+ "<table border=\"1\" class=\"dataframe\">\n",
194
+ " <thead>\n",
195
+ " <tr style=\"text-align: right;\">\n",
196
+ " <th></th>\n",
197
+ " <th>Sno</th>\n",
198
+ " <th>Sex</th>\n",
199
+ " <th>Age</th>\n",
200
+ " <th>Score</th>\n",
201
+ " </tr>\n",
202
+ " </thead>\n",
203
+ " <tbody>\n",
204
+ " <tr>\n",
205
+ " <th>lisi</th>\n",
206
+ " <td>1002</td>\n",
207
+ " <td>woman</td>\n",
208
+ " <td>18</td>\n",
209
+ " <td>97</td>\n",
210
+ " </tr>\n",
211
+ " <tr>\n",
212
+ " <th>ww</th>\n",
213
+ " <td>1003</td>\n",
214
+ " <td>man</td>\n",
215
+ " <td>19</td>\n",
216
+ " <td>95</td>\n",
217
+ " </tr>\n",
218
+ " </tbody>\n",
219
+ "</table>\n",
220
+ "</div>"
221
+ ],
222
+ "text/plain": [
223
+ " Sno Sex Age Score\n",
224
+ "lisi 1002 woman 18 97\n",
225
+ "ww 1003 man 19 95"
226
+ ]
227
+ },
228
+ "execution_count": 19,
229
+ "metadata": {},
230
+ "output_type": "execute_result"
231
+ }
232
+ ],
233
+ "source": [
234
+ "data[scores>scores.mean()]"
235
+ ]
236
+ },
237
+ {
238
+ "cell_type": "code",
239
+ "execution_count": 20,
240
+ "metadata": {},
241
+ "outputs": [
242
+ {
243
+ "data": {
244
+ "text/html": [
245
+ "<div>\n",
246
+ "<style>\n",
247
+ " .dataframe thead tr:only-child th {\n",
248
+ " text-align: right;\n",
249
+ " }\n",
250
+ "\n",
251
+ " .dataframe thead th {\n",
252
+ " text-align: left;\n",
253
+ " }\n",
254
+ "\n",
255
+ " .dataframe tbody tr th {\n",
256
+ " vertical-align: top;\n",
257
+ " }\n",
258
+ "</style>\n",
259
+ "<table border=\"1\" class=\"dataframe\">\n",
260
+ " <thead>\n",
261
+ " <tr style=\"text-align: right;\">\n",
262
+ " <th></th>\n",
263
+ " <th>Sno</th>\n",
264
+ " <th>Sex</th>\n",
265
+ " <th>Age</th>\n",
266
+ " <th>Score</th>\n",
267
+ " </tr>\n",
268
+ " </thead>\n",
269
+ " <tbody>\n",
270
+ " <tr>\n",
271
+ " <th>lisi</th>\n",
272
+ " <td>1002</td>\n",
273
+ " <td>woman</td>\n",
274
+ " <td>18</td>\n",
275
+ " <td>97</td>\n",
276
+ " </tr>\n",
277
+ " </tbody>\n",
278
+ "</table>\n",
279
+ "</div>"
280
+ ],
281
+ "text/plain": [
282
+ " Sno Sex Age Score\n",
283
+ "lisi 1002 woman 18 97"
284
+ ]
285
+ },
286
+ "execution_count": 20,
287
+ "metadata": {},
288
+ "output_type": "execute_result"
289
+ }
290
+ ],
291
+ "source": [
292
+ "data[(scores>scores.mean()) & (ages<19)]"
293
+ ]
294
+ },
295
+ {
296
+ "cell_type": "code",
297
+ "execution_count": 21,
298
+ "metadata": {},
299
+ "outputs": [
300
+ {
301
+ "data": {
302
+ "text/html": [
303
+ "<div>\n",
304
+ "<style>\n",
305
+ " .dataframe thead tr:only-child th {\n",
306
+ " text-align: right;\n",
307
+ " }\n",
308
+ "\n",
309
+ " .dataframe thead th {\n",
310
+ " text-align: left;\n",
311
+ " }\n",
312
+ "\n",
313
+ " .dataframe tbody tr th {\n",
314
+ " vertical-align: top;\n",
315
+ " }\n",
316
+ "</style>\n",
317
+ "<table border=\"1\" class=\"dataframe\">\n",
318
+ " <thead>\n",
319
+ " <tr style=\"text-align: right;\">\n",
320
+ " <th></th>\n",
321
+ " <th>Sno</th>\n",
322
+ " <th>Sex</th>\n",
323
+ " <th>Age</th>\n",
324
+ " <th>Score</th>\n",
325
+ " </tr>\n",
326
+ " </thead>\n",
327
+ " <tbody>\n",
328
+ " <tr>\n",
329
+ " <th>zs</th>\n",
330
+ " <td>1001</td>\n",
331
+ " <td>man</td>\n",
332
+ " <td>17</td>\n",
333
+ " <td>80</td>\n",
334
+ " </tr>\n",
335
+ " <tr>\n",
336
+ " <th>lisi</th>\n",
337
+ " <td>1002</td>\n",
338
+ " <td>woman</td>\n",
339
+ " <td>18</td>\n",
340
+ " <td>97</td>\n",
341
+ " </tr>\n",
342
+ " <tr>\n",
343
+ " <th>ww</th>\n",
344
+ " <td>1003</td>\n",
345
+ " <td>man</td>\n",
346
+ " <td>19</td>\n",
347
+ " <td>95</td>\n",
348
+ " </tr>\n",
349
+ " </tbody>\n",
350
+ "</table>\n",
351
+ "</div>"
352
+ ],
353
+ "text/plain": [
354
+ " Sno Sex Age Score\n",
355
+ "zs 1001 man 17 80\n",
356
+ "lisi 1002 woman 18 97\n",
357
+ "ww 1003 man 19 95"
358
+ ]
359
+ },
360
+ "execution_count": 21,
361
+ "metadata": {},
362
+ "output_type": "execute_result"
363
+ }
364
+ ],
365
+ "source": [
366
+ "data[(scores>scores.mean()) | (ages<19)]"
367
+ ]
368
+ },
369
+ {
370
+ "cell_type": "code",
371
+ "execution_count": 13,
372
+ "metadata": {},
373
+ "outputs": [
374
+ {
375
+ "data": {
376
+ "text/html": [
377
+ "<div>\n",
378
+ "<style>\n",
379
+ " .dataframe thead tr:only-child th {\n",
380
+ " text-align: right;\n",
381
+ " }\n",
382
+ "\n",
383
+ " .dataframe thead th {\n",
384
+ " text-align: left;\n",
385
+ " }\n",
386
+ "\n",
387
+ " .dataframe tbody tr th {\n",
388
+ " vertical-align: top;\n",
389
+ " }\n",
390
+ "</style>\n",
391
+ "<table border=\"1\" class=\"dataframe\">\n",
392
+ " <thead>\n",
393
+ " <tr style=\"text-align: right;\">\n",
394
+ " <th></th>\n",
395
+ " <th>Sno</th>\n",
396
+ " <th>Age</th>\n",
397
+ " <th>Score</th>\n",
398
+ " </tr>\n",
399
+ " </thead>\n",
400
+ " <tbody>\n",
401
+ " <tr>\n",
402
+ " <th>lisi</th>\n",
403
+ " <td>1002</td>\n",
404
+ " <td>18</td>\n",
405
+ " <td>97</td>\n",
406
+ " </tr>\n",
407
+ " <tr>\n",
408
+ " <th>ww</th>\n",
409
+ " <td>1003</td>\n",
410
+ " <td>19</td>\n",
411
+ " <td>95</td>\n",
412
+ " </tr>\n",
413
+ " </tbody>\n",
414
+ "</table>\n",
415
+ "</div>"
416
+ ],
417
+ "text/plain": [
418
+ " Sno Age Score\n",
419
+ "lisi 1002 18 97\n",
420
+ "ww 1003 19 95"
421
+ ]
422
+ },
423
+ "execution_count": 13,
424
+ "metadata": {},
425
+ "output_type": "execute_result"
426
+ }
427
+ ],
428
+ "source": [
429
+ "data[scores>scores.mean()].loc[:,['Sno','Age','Score']]"
430
+ ]
431
+ },
432
+ {
433
+ "cell_type": "code",
434
+ "execution_count": 25,
435
+ "metadata": {},
436
+ "outputs": [
437
+ {
438
+ "data": {
439
+ "text/html": [
440
+ "<div>\n",
441
+ "<style>\n",
442
+ " .dataframe thead tr:only-child th {\n",
443
+ " text-align: right;\n",
444
+ " }\n",
445
+ "\n",
446
+ " .dataframe thead th {\n",
447
+ " text-align: left;\n",
448
+ " }\n",
449
+ "\n",
450
+ " .dataframe tbody tr th {\n",
451
+ " vertical-align: top;\n",
452
+ " }\n",
453
+ "</style>\n",
454
+ "<table border=\"1\" class=\"dataframe\">\n",
455
+ " <thead>\n",
456
+ " <tr style=\"text-align: right;\">\n",
457
+ " <th></th>\n",
458
+ " <th>0</th>\n",
459
+ " <th>1</th>\n",
460
+ " <th>2</th>\n",
461
+ " </tr>\n",
462
+ " </thead>\n",
463
+ " <tbody>\n",
464
+ " <tr>\n",
465
+ " <th>0</th>\n",
466
+ " <td>1</td>\n",
467
+ " <td>2.0</td>\n",
468
+ " <td>NaN</td>\n",
469
+ " </tr>\n",
470
+ " <tr>\n",
471
+ " <th>1</th>\n",
472
+ " <td>4</td>\n",
473
+ " <td>NaN</td>\n",
474
+ " <td>6.0</td>\n",
475
+ " </tr>\n",
476
+ " <tr>\n",
477
+ " <th>2</th>\n",
478
+ " <td>5</td>\n",
479
+ " <td>6.0</td>\n",
480
+ " <td>7.0</td>\n",
481
+ " </tr>\n",
482
+ " </tbody>\n",
483
+ "</table>\n",
484
+ "</div>"
485
+ ],
486
+ "text/plain": [
487
+ " 0 1 2\n",
488
+ "0 1 2.0 NaN\n",
489
+ "1 4 NaN 6.0\n",
490
+ "2 5 6.0 7.0"
491
+ ]
492
+ },
493
+ "execution_count": 25,
494
+ "metadata": {},
495
+ "output_type": "execute_result"
496
+ }
497
+ ],
498
+ "source": [
499
+ "df=pd.DataFrame([[1,2,np.nan],[4,np.nan,6],[5,6,7]])\n",
500
+ "df"
501
+ ]
502
+ },
503
+ {
504
+ "cell_type": "code",
505
+ "execution_count": 26,
506
+ "metadata": {},
507
+ "outputs": [
508
+ {
509
+ "name": "stdout",
510
+ "output_type": "stream",
511
+ "text": [
512
+ "<class 'pandas.core.frame.DataFrame'>\n",
513
+ "RangeIndex: 3 entries, 0 to 2\n",
514
+ "Data columns (total 3 columns):\n",
515
+ "0 3 non-null int64\n",
516
+ "1 2 non-null float64\n",
517
+ "2 2 non-null float64\n",
518
+ "dtypes: float64(2), int64(1)\n",
519
+ "memory usage: 152.0 bytes\n"
520
+ ]
521
+ }
522
+ ],
523
+ "source": [
524
+ "df.info()"
525
+ ]
526
+ },
527
+ {
528
+ "cell_type": "code",
529
+ "execution_count": 29,
530
+ "metadata": {
531
+ "collapsed": true
532
+ },
533
+ "outputs": [],
534
+ "source": [
535
+ "data=pd.Series([3,4,np.nan,1,5,None])"
536
+ ]
537
+ },
538
+ {
539
+ "cell_type": "code",
540
+ "execution_count": 28,
541
+ "metadata": {},
542
+ "outputs": [
543
+ {
544
+ "data": {
545
+ "text/plain": [
546
+ "0 False\n",
547
+ "1 False\n",
548
+ "2 True\n",
549
+ "3 False\n",
550
+ "4 False\n",
551
+ "5 True\n",
552
+ "dtype: bool"
553
+ ]
554
+ },
555
+ "execution_count": 28,
556
+ "metadata": {},
557
+ "output_type": "execute_result"
558
+ }
559
+ ],
560
+ "source": [
561
+ "data.isnull()"
562
+ ]
563
+ },
564
+ {
565
+ "cell_type": "code",
566
+ "execution_count": 30,
567
+ "metadata": {},
568
+ "outputs": [
569
+ {
570
+ "data": {
571
+ "text/plain": [
572
+ "2 NaN\n",
573
+ "5 NaN\n",
574
+ "dtype: float64"
575
+ ]
576
+ },
577
+ "execution_count": 30,
578
+ "metadata": {},
579
+ "output_type": "execute_result"
580
+ }
581
+ ],
582
+ "source": [
583
+ "data[data.isnull()]"
584
+ ]
585
+ },
586
+ {
587
+ "cell_type": "code",
588
+ "execution_count": 31,
589
+ "metadata": {},
590
+ "outputs": [
591
+ {
592
+ "data": {
593
+ "text/plain": [
594
+ "0 3.0\n",
595
+ "1 4.0\n",
596
+ "3 1.0\n",
597
+ "4 5.0\n",
598
+ "dtype: float64"
599
+ ]
600
+ },
601
+ "execution_count": 31,
602
+ "metadata": {},
603
+ "output_type": "execute_result"
604
+ }
605
+ ],
606
+ "source": [
607
+ "data[data.notnull()]"
608
+ ]
609
+ },
610
+ {
611
+ "cell_type": "code",
612
+ "execution_count": 32,
613
+ "metadata": {},
614
+ "outputs": [
615
+ {
616
+ "data": {
617
+ "text/html": [
618
+ "<div>\n",
619
+ "<style>\n",
620
+ " .dataframe thead tr:only-child th {\n",
621
+ " text-align: right;\n",
622
+ " }\n",
623
+ "\n",
624
+ " .dataframe thead th {\n",
625
+ " text-align: left;\n",
626
+ " }\n",
627
+ "\n",
628
+ " .dataframe tbody tr th {\n",
629
+ " vertical-align: top;\n",
630
+ " }\n",
631
+ "</style>\n",
632
+ "<table border=\"1\" class=\"dataframe\">\n",
633
+ " <thead>\n",
634
+ " <tr style=\"text-align: right;\">\n",
635
+ " <th></th>\n",
636
+ " <th>0</th>\n",
637
+ " <th>1</th>\n",
638
+ " <th>2</th>\n",
639
+ " </tr>\n",
640
+ " </thead>\n",
641
+ " <tbody>\n",
642
+ " <tr>\n",
643
+ " <th>0</th>\n",
644
+ " <td>1</td>\n",
645
+ " <td>2.0</td>\n",
646
+ " <td>NaN</td>\n",
647
+ " </tr>\n",
648
+ " <tr>\n",
649
+ " <th>1</th>\n",
650
+ " <td>4</td>\n",
651
+ " <td>NaN</td>\n",
652
+ " <td>6.0</td>\n",
653
+ " </tr>\n",
654
+ " <tr>\n",
655
+ " <th>2</th>\n",
656
+ " <td>5</td>\n",
657
+ " <td>6.0</td>\n",
658
+ " <td>7.0</td>\n",
659
+ " </tr>\n",
660
+ " </tbody>\n",
661
+ "</table>\n",
662
+ "</div>"
663
+ ],
664
+ "text/plain": [
665
+ " 0 1 2\n",
666
+ "0 1 2.0 NaN\n",
667
+ "1 4 NaN 6.0\n",
668
+ "2 5 6.0 7.0"
669
+ ]
670
+ },
671
+ "execution_count": 32,
672
+ "metadata": {},
673
+ "output_type": "execute_result"
674
+ }
675
+ ],
676
+ "source": [
677
+ "df=pd.DataFrame([[1,2,np.nan],[4,np.nan,6],[5,6,7]])\n",
678
+ "df"
679
+ ]
680
+ },
681
+ {
682
+ "cell_type": "code",
683
+ "execution_count": 35,
684
+ "metadata": {},
685
+ "outputs": [
686
+ {
687
+ "data": {
688
+ "text/html": [
689
+ "<div>\n",
690
+ "<style>\n",
691
+ " .dataframe thead tr:only-child th {\n",
692
+ " text-align: right;\n",
693
+ " }\n",
694
+ "\n",
695
+ " .dataframe thead th {\n",
696
+ " text-align: left;\n",
697
+ " }\n",
698
+ "\n",
699
+ " .dataframe tbody tr th {\n",
700
+ " vertical-align: top;\n",
701
+ " }\n",
702
+ "</style>\n",
703
+ "<table border=\"1\" class=\"dataframe\">\n",
704
+ " <thead>\n",
705
+ " <tr style=\"text-align: right;\">\n",
706
+ " <th></th>\n",
707
+ " <th>0</th>\n",
708
+ " <th>1</th>\n",
709
+ " <th>2</th>\n",
710
+ " </tr>\n",
711
+ " </thead>\n",
712
+ " <tbody>\n",
713
+ " <tr>\n",
714
+ " <th>2</th>\n",
715
+ " <td>5</td>\n",
716
+ " <td>6.0</td>\n",
717
+ " <td>7.0</td>\n",
718
+ " </tr>\n",
719
+ " </tbody>\n",
720
+ "</table>\n",
721
+ "</div>"
722
+ ],
723
+ "text/plain": [
724
+ " 0 1 2\n",
725
+ "2 5 6.0 7.0"
726
+ ]
727
+ },
728
+ "execution_count": 35,
729
+ "metadata": {},
730
+ "output_type": "execute_result"
731
+ }
732
+ ],
733
+ "source": [
734
+ "new_df = df.dropna()\n",
735
+ "new_df"
736
+ ]
737
+ },
738
+ {
739
+ "cell_type": "code",
740
+ "execution_count": 34,
741
+ "metadata": {},
742
+ "outputs": [
743
+ {
744
+ "data": {
745
+ "text/html": [
746
+ "<div>\n",
747
+ "<style>\n",
748
+ " .dataframe thead tr:only-child th {\n",
749
+ " text-align: right;\n",
750
+ " }\n",
751
+ "\n",
752
+ " .dataframe thead th {\n",
753
+ " text-align: left;\n",
754
+ " }\n",
755
+ "\n",
756
+ " .dataframe tbody tr th {\n",
757
+ " vertical-align: top;\n",
758
+ " }\n",
759
+ "</style>\n",
760
+ "<table border=\"1\" class=\"dataframe\">\n",
761
+ " <thead>\n",
762
+ " <tr style=\"text-align: right;\">\n",
763
+ " <th></th>\n",
764
+ " <th>0</th>\n",
765
+ " <th>1</th>\n",
766
+ " <th>2</th>\n",
767
+ " </tr>\n",
768
+ " </thead>\n",
769
+ " <tbody>\n",
770
+ " <tr>\n",
771
+ " <th>0</th>\n",
772
+ " <td>1</td>\n",
773
+ " <td>2.0</td>\n",
774
+ " <td>NaN</td>\n",
775
+ " </tr>\n",
776
+ " <tr>\n",
777
+ " <th>1</th>\n",
778
+ " <td>4</td>\n",
779
+ " <td>NaN</td>\n",
780
+ " <td>6.0</td>\n",
781
+ " </tr>\n",
782
+ " <tr>\n",
783
+ " <th>2</th>\n",
784
+ " <td>5</td>\n",
785
+ " <td>6.0</td>\n",
786
+ " <td>7.0</td>\n",
787
+ " </tr>\n",
788
+ " </tbody>\n",
789
+ "</table>\n",
790
+ "</div>"
791
+ ],
792
+ "text/plain": [
793
+ " 0 1 2\n",
794
+ "0 1 2.0 NaN\n",
795
+ "1 4 NaN 6.0\n",
796
+ "2 5 6.0 7.0"
797
+ ]
798
+ },
799
+ "execution_count": 34,
800
+ "metadata": {},
801
+ "output_type": "execute_result"
802
+ }
803
+ ],
804
+ "source": [
805
+ "df"
806
+ ]
807
+ },
808
+ {
809
+ "cell_type": "code",
810
+ "execution_count": 36,
811
+ "metadata": {},
812
+ "outputs": [
813
+ {
814
+ "data": {
815
+ "text/html": [
816
+ "<div>\n",
817
+ "<style>\n",
818
+ " .dataframe thead tr:only-child th {\n",
819
+ " text-align: right;\n",
820
+ " }\n",
821
+ "\n",
822
+ " .dataframe thead th {\n",
823
+ " text-align: left;\n",
824
+ " }\n",
825
+ "\n",
826
+ " .dataframe tbody tr th {\n",
827
+ " vertical-align: top;\n",
828
+ " }\n",
829
+ "</style>\n",
830
+ "<table border=\"1\" class=\"dataframe\">\n",
831
+ " <thead>\n",
832
+ " <tr style=\"text-align: right;\">\n",
833
+ " <th></th>\n",
834
+ " <th>0</th>\n",
835
+ " </tr>\n",
836
+ " </thead>\n",
837
+ " <tbody>\n",
838
+ " <tr>\n",
839
+ " <th>0</th>\n",
840
+ " <td>1</td>\n",
841
+ " </tr>\n",
842
+ " <tr>\n",
843
+ " <th>1</th>\n",
844
+ " <td>4</td>\n",
845
+ " </tr>\n",
846
+ " <tr>\n",
847
+ " <th>2</th>\n",
848
+ " <td>5</td>\n",
849
+ " </tr>\n",
850
+ " </tbody>\n",
851
+ "</table>\n",
852
+ "</div>"
853
+ ],
854
+ "text/plain": [
855
+ " 0\n",
856
+ "0 1\n",
857
+ "1 4\n",
858
+ "2 5"
859
+ ]
860
+ },
861
+ "execution_count": 36,
862
+ "metadata": {},
863
+ "output_type": "execute_result"
864
+ }
865
+ ],
866
+ "source": [
867
+ "df.dropna(axis='columns')"
868
+ ]
869
+ },
870
+ {
871
+ "cell_type": "code",
872
+ "execution_count": 37,
873
+ "metadata": {},
874
+ "outputs": [
875
+ {
876
+ "data": {
877
+ "text/html": [
878
+ "<div>\n",
879
+ "<style>\n",
880
+ " .dataframe thead tr:only-child th {\n",
881
+ " text-align: right;\n",
882
+ " }\n",
883
+ "\n",
884
+ " .dataframe thead th {\n",
885
+ " text-align: left;\n",
886
+ " }\n",
887
+ "\n",
888
+ " .dataframe tbody tr th {\n",
889
+ " vertical-align: top;\n",
890
+ " }\n",
891
+ "</style>\n",
892
+ "<table border=\"1\" class=\"dataframe\">\n",
893
+ " <thead>\n",
894
+ " <tr style=\"text-align: right;\">\n",
895
+ " <th></th>\n",
896
+ " <th>0</th>\n",
897
+ " <th>1</th>\n",
898
+ " <th>2</th>\n",
899
+ " </tr>\n",
900
+ " </thead>\n",
901
+ " <tbody>\n",
902
+ " <tr>\n",
903
+ " <th>0</th>\n",
904
+ " <td>1</td>\n",
905
+ " <td>2.0</td>\n",
906
+ " <td>NaN</td>\n",
907
+ " </tr>\n",
908
+ " <tr>\n",
909
+ " <th>1</th>\n",
910
+ " <td>4</td>\n",
911
+ " <td>NaN</td>\n",
912
+ " <td>6.0</td>\n",
913
+ " </tr>\n",
914
+ " <tr>\n",
915
+ " <th>2</th>\n",
916
+ " <td>5</td>\n",
917
+ " <td>6.0</td>\n",
918
+ " <td>7.0</td>\n",
919
+ " </tr>\n",
920
+ " </tbody>\n",
921
+ "</table>\n",
922
+ "</div>"
923
+ ],
924
+ "text/plain": [
925
+ " 0 1 2\n",
926
+ "0 1 2.0 NaN\n",
927
+ "1 4 NaN 6.0\n",
928
+ "2 5 6.0 7.0"
929
+ ]
930
+ },
931
+ "execution_count": 37,
932
+ "metadata": {},
933
+ "output_type": "execute_result"
934
+ }
935
+ ],
936
+ "source": [
937
+ "df.dropna(how='all')"
938
+ ]
939
+ },
940
+ {
941
+ "cell_type": "code",
942
+ "execution_count": 39,
943
+ "metadata": {},
944
+ "outputs": [
945
+ {
946
+ "data": {
947
+ "text/plain": [
948
+ "0 3.0\n",
949
+ "1 4.0\n",
950
+ "2 NaN\n",
951
+ "3 1.0\n",
952
+ "4 5.0\n",
953
+ "5 NaN\n",
954
+ "dtype: float64"
955
+ ]
956
+ },
957
+ "execution_count": 39,
958
+ "metadata": {},
959
+ "output_type": "execute_result"
960
+ }
961
+ ],
962
+ "source": [
963
+ "data=pd.Series([3,4,np.nan,1,5,None])\n",
964
+ "data"
965
+ ]
966
+ },
967
+ {
968
+ "cell_type": "code",
969
+ "execution_count": 40,
970
+ "metadata": {},
971
+ "outputs": [
972
+ {
973
+ "data": {
974
+ "text/plain": [
975
+ "0 3.0\n",
976
+ "1 4.0\n",
977
+ "2 0.0\n",
978
+ "3 1.0\n",
979
+ "4 5.0\n",
980
+ "5 0.0\n",
981
+ "dtype: float64"
982
+ ]
983
+ },
984
+ "execution_count": 40,
985
+ "metadata": {},
986
+ "output_type": "execute_result"
987
+ }
988
+ ],
989
+ "source": [
990
+ "data.fillna(0)"
991
+ ]
992
+ },
993
+ {
994
+ "cell_type": "code",
995
+ "execution_count": 41,
996
+ "metadata": {},
997
+ "outputs": [
998
+ {
999
+ "data": {
1000
+ "text/plain": [
1001
+ "0 3.0\n",
1002
+ "1 4.0\n",
1003
+ "2 4.0\n",
1004
+ "3 1.0\n",
1005
+ "4 5.0\n",
1006
+ "5 5.0\n",
1007
+ "dtype: float64"
1008
+ ]
1009
+ },
1010
+ "execution_count": 41,
1011
+ "metadata": {},
1012
+ "output_type": "execute_result"
1013
+ }
1014
+ ],
1015
+ "source": [
1016
+ "data.fillna(method='ffill')"
1017
+ ]
1018
+ },
1019
+ {
1020
+ "cell_type": "code",
1021
+ "execution_count": 42,
1022
+ "metadata": {},
1023
+ "outputs": [
1024
+ {
1025
+ "data": {
1026
+ "text/plain": [
1027
+ "0 3.0\n",
1028
+ "1 4.0\n",
1029
+ "2 1.0\n",
1030
+ "3 1.0\n",
1031
+ "4 5.0\n",
1032
+ "5 NaN\n",
1033
+ "dtype: float64"
1034
+ ]
1035
+ },
1036
+ "execution_count": 42,
1037
+ "metadata": {},
1038
+ "output_type": "execute_result"
1039
+ }
1040
+ ],
1041
+ "source": [
1042
+ "data.fillna(method='bfill')"
1043
+ ]
1044
+ },
1045
+ {
1046
+ "cell_type": "code",
1047
+ "execution_count": 43,
1048
+ "metadata": {},
1049
+ "outputs": [
1050
+ {
1051
+ "data": {
1052
+ "text/html": [
1053
+ "<div>\n",
1054
+ "<style>\n",
1055
+ " .dataframe thead tr:only-child th {\n",
1056
+ " text-align: right;\n",
1057
+ " }\n",
1058
+ "\n",
1059
+ " .dataframe thead th {\n",
1060
+ " text-align: left;\n",
1061
+ " }\n",
1062
+ "\n",
1063
+ " .dataframe tbody tr th {\n",
1064
+ " vertical-align: top;\n",
1065
+ " }\n",
1066
+ "</style>\n",
1067
+ "<table border=\"1\" class=\"dataframe\">\n",
1068
+ " <thead>\n",
1069
+ " <tr style=\"text-align: right;\">\n",
1070
+ " <th></th>\n",
1071
+ " <th>0</th>\n",
1072
+ " <th>1</th>\n",
1073
+ " <th>2</th>\n",
1074
+ " </tr>\n",
1075
+ " </thead>\n",
1076
+ " <tbody>\n",
1077
+ " <tr>\n",
1078
+ " <th>0</th>\n",
1079
+ " <td>1</td>\n",
1080
+ " <td>2.0</td>\n",
1081
+ " <td>NaN</td>\n",
1082
+ " </tr>\n",
1083
+ " <tr>\n",
1084
+ " <th>1</th>\n",
1085
+ " <td>4</td>\n",
1086
+ " <td>NaN</td>\n",
1087
+ " <td>6.0</td>\n",
1088
+ " </tr>\n",
1089
+ " <tr>\n",
1090
+ " <th>2</th>\n",
1091
+ " <td>5</td>\n",
1092
+ " <td>6.0</td>\n",
1093
+ " <td>7.0</td>\n",
1094
+ " </tr>\n",
1095
+ " </tbody>\n",
1096
+ "</table>\n",
1097
+ "</div>"
1098
+ ],
1099
+ "text/plain": [
1100
+ " 0 1 2\n",
1101
+ "0 1 2.0 NaN\n",
1102
+ "1 4 NaN 6.0\n",
1103
+ "2 5 6.0 7.0"
1104
+ ]
1105
+ },
1106
+ "execution_count": 43,
1107
+ "metadata": {},
1108
+ "output_type": "execute_result"
1109
+ }
1110
+ ],
1111
+ "source": [
1112
+ "df=pd.DataFrame([[1,2,np.nan],[4,np.nan,6],[5,6,7]])\n",
1113
+ "df"
1114
+ ]
1115
+ },
1116
+ {
1117
+ "cell_type": "code",
1118
+ "execution_count": 44,
1119
+ "metadata": {},
1120
+ "outputs": [
1121
+ {
1122
+ "data": {
1123
+ "text/html": [
1124
+ "<div>\n",
1125
+ "<style>\n",
1126
+ " .dataframe thead tr:only-child th {\n",
1127
+ " text-align: right;\n",
1128
+ " }\n",
1129
+ "\n",
1130
+ " .dataframe thead th {\n",
1131
+ " text-align: left;\n",
1132
+ " }\n",
1133
+ "\n",
1134
+ " .dataframe tbody tr th {\n",
1135
+ " vertical-align: top;\n",
1136
+ " }\n",
1137
+ "</style>\n",
1138
+ "<table border=\"1\" class=\"dataframe\">\n",
1139
+ " <thead>\n",
1140
+ " <tr style=\"text-align: right;\">\n",
1141
+ " <th></th>\n",
1142
+ " <th>0</th>\n",
1143
+ " <th>1</th>\n",
1144
+ " <th>2</th>\n",
1145
+ " </tr>\n",
1146
+ " </thead>\n",
1147
+ " <tbody>\n",
1148
+ " <tr>\n",
1149
+ " <th>0</th>\n",
1150
+ " <td>1</td>\n",
1151
+ " <td>2.0</td>\n",
1152
+ " <td>0.0</td>\n",
1153
+ " </tr>\n",
1154
+ " <tr>\n",
1155
+ " <th>1</th>\n",
1156
+ " <td>4</td>\n",
1157
+ " <td>0.0</td>\n",
1158
+ " <td>6.0</td>\n",
1159
+ " </tr>\n",
1160
+ " <tr>\n",
1161
+ " <th>2</th>\n",
1162
+ " <td>5</td>\n",
1163
+ " <td>6.0</td>\n",
1164
+ " <td>7.0</td>\n",
1165
+ " </tr>\n",
1166
+ " </tbody>\n",
1167
+ "</table>\n",
1168
+ "</div>"
1169
+ ],
1170
+ "text/plain": [
1171
+ " 0 1 2\n",
1172
+ "0 1 2.0 0.0\n",
1173
+ "1 4 0.0 6.0\n",
1174
+ "2 5 6.0 7.0"
1175
+ ]
1176
+ },
1177
+ "execution_count": 44,
1178
+ "metadata": {},
1179
+ "output_type": "execute_result"
1180
+ }
1181
+ ],
1182
+ "source": [
1183
+ "df.fillna(0)"
1184
+ ]
1185
+ },
1186
+ {
1187
+ "cell_type": "code",
1188
+ "execution_count": 45,
1189
+ "metadata": {},
1190
+ "outputs": [
1191
+ {
1192
+ "data": {
1193
+ "text/html": [
1194
+ "<div>\n",
1195
+ "<style>\n",
1196
+ " .dataframe thead tr:only-child th {\n",
1197
+ " text-align: right;\n",
1198
+ " }\n",
1199
+ "\n",
1200
+ " .dataframe thead th {\n",
1201
+ " text-align: left;\n",
1202
+ " }\n",
1203
+ "\n",
1204
+ " .dataframe tbody tr th {\n",
1205
+ " vertical-align: top;\n",
1206
+ " }\n",
1207
+ "</style>\n",
1208
+ "<table border=\"1\" class=\"dataframe\">\n",
1209
+ " <thead>\n",
1210
+ " <tr style=\"text-align: right;\">\n",
1211
+ " <th></th>\n",
1212
+ " <th>0</th>\n",
1213
+ " <th>1</th>\n",
1214
+ " <th>2</th>\n",
1215
+ " </tr>\n",
1216
+ " </thead>\n",
1217
+ " <tbody>\n",
1218
+ " <tr>\n",
1219
+ " <th>0</th>\n",
1220
+ " <td>1</td>\n",
1221
+ " <td>2.0</td>\n",
1222
+ " <td>NaN</td>\n",
1223
+ " </tr>\n",
1224
+ " <tr>\n",
1225
+ " <th>1</th>\n",
1226
+ " <td>4</td>\n",
1227
+ " <td>2.0</td>\n",
1228
+ " <td>6.0</td>\n",
1229
+ " </tr>\n",
1230
+ " <tr>\n",
1231
+ " <th>2</th>\n",
1232
+ " <td>5</td>\n",
1233
+ " <td>6.0</td>\n",
1234
+ " <td>7.0</td>\n",
1235
+ " </tr>\n",
1236
+ " </tbody>\n",
1237
+ "</table>\n",
1238
+ "</div>"
1239
+ ],
1240
+ "text/plain": [
1241
+ " 0 1 2\n",
1242
+ "0 1 2.0 NaN\n",
1243
+ "1 4 2.0 6.0\n",
1244
+ "2 5 6.0 7.0"
1245
+ ]
1246
+ },
1247
+ "execution_count": 45,
1248
+ "metadata": {},
1249
+ "output_type": "execute_result"
1250
+ }
1251
+ ],
1252
+ "source": [
1253
+ "df.fillna(method='ffill')"
1254
+ ]
1255
+ },
1256
+ {
1257
+ "cell_type": "code",
1258
+ "execution_count": 47,
1259
+ "metadata": {},
1260
+ "outputs": [
1261
+ {
1262
+ "data": {
1263
+ "text/html": [
1264
+ "<div>\n",
1265
+ "<style>\n",
1266
+ " .dataframe thead tr:only-child th {\n",
1267
+ " text-align: right;\n",
1268
+ " }\n",
1269
+ "\n",
1270
+ " .dataframe thead th {\n",
1271
+ " text-align: left;\n",
1272
+ " }\n",
1273
+ "\n",
1274
+ " .dataframe tbody tr th {\n",
1275
+ " vertical-align: top;\n",
1276
+ " }\n",
1277
+ "</style>\n",
1278
+ "<table border=\"1\" class=\"dataframe\">\n",
1279
+ " <thead>\n",
1280
+ " <tr style=\"text-align: right;\">\n",
1281
+ " <th></th>\n",
1282
+ " <th>0</th>\n",
1283
+ " <th>1</th>\n",
1284
+ " <th>2</th>\n",
1285
+ " </tr>\n",
1286
+ " </thead>\n",
1287
+ " <tbody>\n",
1288
+ " <tr>\n",
1289
+ " <th>0</th>\n",
1290
+ " <td>1.0</td>\n",
1291
+ " <td>2.0</td>\n",
1292
+ " <td>NaN</td>\n",
1293
+ " </tr>\n",
1294
+ " <tr>\n",
1295
+ " <th>1</th>\n",
1296
+ " <td>4.0</td>\n",
1297
+ " <td>6.0</td>\n",
1298
+ " <td>6.0</td>\n",
1299
+ " </tr>\n",
1300
+ " <tr>\n",
1301
+ " <th>2</th>\n",
1302
+ " <td>5.0</td>\n",
1303
+ " <td>6.0</td>\n",
1304
+ " <td>7.0</td>\n",
1305
+ " </tr>\n",
1306
+ " </tbody>\n",
1307
+ "</table>\n",
1308
+ "</div>"
1309
+ ],
1310
+ "text/plain": [
1311
+ " 0 1 2\n",
1312
+ "0 1.0 2.0 NaN\n",
1313
+ "1 4.0 6.0 6.0\n",
1314
+ "2 5.0 6.0 7.0"
1315
+ ]
1316
+ },
1317
+ "execution_count": 47,
1318
+ "metadata": {},
1319
+ "output_type": "execute_result"
1320
+ }
1321
+ ],
1322
+ "source": [
1323
+ "df.fillna(method='bfill', axis=1)"
1324
+ ]
1325
+ },
1326
+ {
1327
+ "cell_type": "code",
1328
+ "execution_count": 48,
1329
+ "metadata": {},
1330
+ "outputs": [
1331
+ {
1332
+ "data": {
1333
+ "text/html": [
1334
+ "<div>\n",
1335
+ "<style>\n",
1336
+ " .dataframe thead tr:only-child th {\n",
1337
+ " text-align: right;\n",
1338
+ " }\n",
1339
+ "\n",
1340
+ " .dataframe thead th {\n",
1341
+ " text-align: left;\n",
1342
+ " }\n",
1343
+ "\n",
1344
+ " .dataframe tbody tr th {\n",
1345
+ " vertical-align: top;\n",
1346
+ " }\n",
1347
+ "</style>\n",
1348
+ "<table border=\"1\" class=\"dataframe\">\n",
1349
+ " <thead>\n",
1350
+ " <tr style=\"text-align: right;\">\n",
1351
+ " <th></th>\n",
1352
+ " <th>0</th>\n",
1353
+ " <th>1</th>\n",
1354
+ " <th>2</th>\n",
1355
+ " </tr>\n",
1356
+ " </thead>\n",
1357
+ " <tbody>\n",
1358
+ " <tr>\n",
1359
+ " <th>0</th>\n",
1360
+ " <td>1</td>\n",
1361
+ " <td>2.0</td>\n",
1362
+ " <td>NaN</td>\n",
1363
+ " </tr>\n",
1364
+ " <tr>\n",
1365
+ " <th>1</th>\n",
1366
+ " <td>4</td>\n",
1367
+ " <td>NaN</td>\n",
1368
+ " <td>6.0</td>\n",
1369
+ " </tr>\n",
1370
+ " <tr>\n",
1371
+ " <th>2</th>\n",
1372
+ " <td>5</td>\n",
1373
+ " <td>6.0</td>\n",
1374
+ " <td>7.0</td>\n",
1375
+ " </tr>\n",
1376
+ " </tbody>\n",
1377
+ "</table>\n",
1378
+ "</div>"
1379
+ ],
1380
+ "text/plain": [
1381
+ " 0 1 2\n",
1382
+ "0 1 2.0 NaN\n",
1383
+ "1 4 NaN 6.0\n",
1384
+ "2 5 6.0 7.0"
1385
+ ]
1386
+ },
1387
+ "execution_count": 48,
1388
+ "metadata": {},
1389
+ "output_type": "execute_result"
1390
+ }
1391
+ ],
1392
+ "source": [
1393
+ "df"
1394
+ ]
1395
+ },
1396
+ {
1397
+ "cell_type": "code",
1398
+ "execution_count": 56,
1399
+ "metadata": {
1400
+ "collapsed": true
1401
+ },
1402
+ "outputs": [],
1403
+ "source": [
1404
+ "for i in df.columns:\n",
1405
+ " df[i] = df[i].fillna(np.nanmean(df[i]))"
1406
+ ]
1407
+ },
1408
+ {
1409
+ "cell_type": "code",
1410
+ "execution_count": 57,
1411
+ "metadata": {},
1412
+ "outputs": [
1413
+ {
1414
+ "data": {
1415
+ "text/html": [
1416
+ "<div>\n",
1417
+ "<style>\n",
1418
+ " .dataframe thead tr:only-child th {\n",
1419
+ " text-align: right;\n",
1420
+ " }\n",
1421
+ "\n",
1422
+ " .dataframe thead th {\n",
1423
+ " text-align: left;\n",
1424
+ " }\n",
1425
+ "\n",
1426
+ " .dataframe tbody tr th {\n",
1427
+ " vertical-align: top;\n",
1428
+ " }\n",
1429
+ "</style>\n",
1430
+ "<table border=\"1\" class=\"dataframe\">\n",
1431
+ " <thead>\n",
1432
+ " <tr style=\"text-align: right;\">\n",
1433
+ " <th></th>\n",
1434
+ " <th>0</th>\n",
1435
+ " <th>1</th>\n",
1436
+ " <th>2</th>\n",
1437
+ " </tr>\n",
1438
+ " </thead>\n",
1439
+ " <tbody>\n",
1440
+ " <tr>\n",
1441
+ " <th>0</th>\n",
1442
+ " <td>1</td>\n",
1443
+ " <td>2.0</td>\n",
1444
+ " <td>6.5</td>\n",
1445
+ " </tr>\n",
1446
+ " <tr>\n",
1447
+ " <th>1</th>\n",
1448
+ " <td>4</td>\n",
1449
+ " <td>4.0</td>\n",
1450
+ " <td>6.0</td>\n",
1451
+ " </tr>\n",
1452
+ " <tr>\n",
1453
+ " <th>2</th>\n",
1454
+ " <td>5</td>\n",
1455
+ " <td>6.0</td>\n",
1456
+ " <td>7.0</td>\n",
1457
+ " </tr>\n",
1458
+ " </tbody>\n",
1459
+ "</table>\n",
1460
+ "</div>"
1461
+ ],
1462
+ "text/plain": [
1463
+ " 0 1 2\n",
1464
+ "0 1 2.0 6.5\n",
1465
+ "1 4 4.0 6.0\n",
1466
+ "2 5 6.0 7.0"
1467
+ ]
1468
+ },
1469
+ "execution_count": 57,
1470
+ "metadata": {},
1471
+ "output_type": "execute_result"
1472
+ }
1473
+ ],
1474
+ "source": [
1475
+ "df"
1476
+ ]
1477
+ },
1478
+ {
1479
+ "cell_type": "code",
1480
+ "execution_count": 58,
1481
+ "metadata": {},
1482
+ "outputs": [
1483
+ {
1484
+ "data": {
1485
+ "text/plain": [
1486
+ "A 1\n",
1487
+ "B 2\n",
1488
+ "C 3\n",
1489
+ "D 4\n",
1490
+ "E 5\n",
1491
+ "F 6\n",
1492
+ "dtype: int64"
1493
+ ]
1494
+ },
1495
+ "execution_count": 58,
1496
+ "metadata": {},
1497
+ "output_type": "execute_result"
1498
+ }
1499
+ ],
1500
+ "source": [
1501
+ "ser1=pd.Series([1,2,3],index=list('ABC'))\n",
1502
+ "ser2=pd.Series([4,5,6],index=list('DEF'))\n",
1503
+ "pd.concat([ser1,ser2])"
1504
+ ]
1505
+ },
1506
+ {
1507
+ "cell_type": "code",
1508
+ "execution_count": 59,
1509
+ "metadata": {
1510
+ "collapsed": true
1511
+ },
1512
+ "outputs": [],
1513
+ "source": [
1514
+ "def make_df(cols,index):\n",
1515
+ " data={c:[str(c)+str(i) for i in index] for c in cols}\n",
1516
+ " return pd.DataFrame(data,index=index)\n",
1517
+ "df1=make_df('AB',[1,2])\n",
1518
+ "df2=make_df('AB',[3,4])"
1519
+ ]
1520
+ },
1521
+ {
1522
+ "cell_type": "code",
1523
+ "execution_count": 60,
1524
+ "metadata": {},
1525
+ "outputs": [
1526
+ {
1527
+ "data": {
1528
+ "text/html": [
1529
+ "<div>\n",
1530
+ "<style>\n",
1531
+ " .dataframe thead tr:only-child th {\n",
1532
+ " text-align: right;\n",
1533
+ " }\n",
1534
+ "\n",
1535
+ " .dataframe thead th {\n",
1536
+ " text-align: left;\n",
1537
+ " }\n",
1538
+ "\n",
1539
+ " .dataframe tbody tr th {\n",
1540
+ " vertical-align: top;\n",
1541
+ " }\n",
1542
+ "</style>\n",
1543
+ "<table border=\"1\" class=\"dataframe\">\n",
1544
+ " <thead>\n",
1545
+ " <tr style=\"text-align: right;\">\n",
1546
+ " <th></th>\n",
1547
+ " <th>A</th>\n",
1548
+ " <th>B</th>\n",
1549
+ " </tr>\n",
1550
+ " </thead>\n",
1551
+ " <tbody>\n",
1552
+ " <tr>\n",
1553
+ " <th>1</th>\n",
1554
+ " <td>A1</td>\n",
1555
+ " <td>B1</td>\n",
1556
+ " </tr>\n",
1557
+ " <tr>\n",
1558
+ " <th>2</th>\n",
1559
+ " <td>A2</td>\n",
1560
+ " <td>B2</td>\n",
1561
+ " </tr>\n",
1562
+ " </tbody>\n",
1563
+ "</table>\n",
1564
+ "</div>"
1565
+ ],
1566
+ "text/plain": [
1567
+ " A B\n",
1568
+ "1 A1 B1\n",
1569
+ "2 A2 B2"
1570
+ ]
1571
+ },
1572
+ "execution_count": 60,
1573
+ "metadata": {},
1574
+ "output_type": "execute_result"
1575
+ }
1576
+ ],
1577
+ "source": [
1578
+ "df1"
1579
+ ]
1580
+ },
1581
+ {
1582
+ "cell_type": "code",
1583
+ "execution_count": 61,
1584
+ "metadata": {},
1585
+ "outputs": [
1586
+ {
1587
+ "data": {
1588
+ "text/html": [
1589
+ "<div>\n",
1590
+ "<style>\n",
1591
+ " .dataframe thead tr:only-child th {\n",
1592
+ " text-align: right;\n",
1593
+ " }\n",
1594
+ "\n",
1595
+ " .dataframe thead th {\n",
1596
+ " text-align: left;\n",
1597
+ " }\n",
1598
+ "\n",
1599
+ " .dataframe tbody tr th {\n",
1600
+ " vertical-align: top;\n",
1601
+ " }\n",
1602
+ "</style>\n",
1603
+ "<table border=\"1\" class=\"dataframe\">\n",
1604
+ " <thead>\n",
1605
+ " <tr style=\"text-align: right;\">\n",
1606
+ " <th></th>\n",
1607
+ " <th>A</th>\n",
1608
+ " <th>B</th>\n",
1609
+ " </tr>\n",
1610
+ " </thead>\n",
1611
+ " <tbody>\n",
1612
+ " <tr>\n",
1613
+ " <th>3</th>\n",
1614
+ " <td>A3</td>\n",
1615
+ " <td>B3</td>\n",
1616
+ " </tr>\n",
1617
+ " <tr>\n",
1618
+ " <th>4</th>\n",
1619
+ " <td>A4</td>\n",
1620
+ " <td>B4</td>\n",
1621
+ " </tr>\n",
1622
+ " </tbody>\n",
1623
+ "</table>\n",
1624
+ "</div>"
1625
+ ],
1626
+ "text/plain": [
1627
+ " A B\n",
1628
+ "3 A3 B3\n",
1629
+ "4 A4 B4"
1630
+ ]
1631
+ },
1632
+ "execution_count": 61,
1633
+ "metadata": {},
1634
+ "output_type": "execute_result"
1635
+ }
1636
+ ],
1637
+ "source": [
1638
+ "df2"
1639
+ ]
1640
+ },
1641
+ {
1642
+ "cell_type": "code",
1643
+ "execution_count": 62,
1644
+ "metadata": {},
1645
+ "outputs": [
1646
+ {
1647
+ "data": {
1648
+ "text/html": [
1649
+ "<div>\n",
1650
+ "<style>\n",
1651
+ " .dataframe thead tr:only-child th {\n",
1652
+ " text-align: right;\n",
1653
+ " }\n",
1654
+ "\n",
1655
+ " .dataframe thead th {\n",
1656
+ " text-align: left;\n",
1657
+ " }\n",
1658
+ "\n",
1659
+ " .dataframe tbody tr th {\n",
1660
+ " vertical-align: top;\n",
1661
+ " }\n",
1662
+ "</style>\n",
1663
+ "<table border=\"1\" class=\"dataframe\">\n",
1664
+ " <thead>\n",
1665
+ " <tr style=\"text-align: right;\">\n",
1666
+ " <th></th>\n",
1667
+ " <th>A</th>\n",
1668
+ " <th>B</th>\n",
1669
+ " </tr>\n",
1670
+ " </thead>\n",
1671
+ " <tbody>\n",
1672
+ " <tr>\n",
1673
+ " <th>1</th>\n",
1674
+ " <td>A1</td>\n",
1675
+ " <td>B1</td>\n",
1676
+ " </tr>\n",
1677
+ " <tr>\n",
1678
+ " <th>2</th>\n",
1679
+ " <td>A2</td>\n",
1680
+ " <td>B2</td>\n",
1681
+ " </tr>\n",
1682
+ " <tr>\n",
1683
+ " <th>3</th>\n",
1684
+ " <td>A3</td>\n",
1685
+ " <td>B3</td>\n",
1686
+ " </tr>\n",
1687
+ " <tr>\n",
1688
+ " <th>4</th>\n",
1689
+ " <td>A4</td>\n",
1690
+ " <td>B4</td>\n",
1691
+ " </tr>\n",
1692
+ " </tbody>\n",
1693
+ "</table>\n",
1694
+ "</div>"
1695
+ ],
1696
+ "text/plain": [
1697
+ " A B\n",
1698
+ "1 A1 B1\n",
1699
+ "2 A2 B2\n",
1700
+ "3 A3 B3\n",
1701
+ "4 A4 B4"
1702
+ ]
1703
+ },
1704
+ "execution_count": 62,
1705
+ "metadata": {},
1706
+ "output_type": "execute_result"
1707
+ }
1708
+ ],
1709
+ "source": [
1710
+ "pd.concat([df1, df2])"
1711
+ ]
1712
+ },
1713
+ {
1714
+ "cell_type": "code",
1715
+ "execution_count": 63,
1716
+ "metadata": {},
1717
+ "outputs": [
1718
+ {
1719
+ "data": {
1720
+ "text/html": [
1721
+ "<div>\n",
1722
+ "<style>\n",
1723
+ " .dataframe thead tr:only-child th {\n",
1724
+ " text-align: right;\n",
1725
+ " }\n",
1726
+ "\n",
1727
+ " .dataframe thead th {\n",
1728
+ " text-align: left;\n",
1729
+ " }\n",
1730
+ "\n",
1731
+ " .dataframe tbody tr th {\n",
1732
+ " vertical-align: top;\n",
1733
+ " }\n",
1734
+ "</style>\n",
1735
+ "<table border=\"1\" class=\"dataframe\">\n",
1736
+ " <thead>\n",
1737
+ " <tr style=\"text-align: right;\">\n",
1738
+ " <th></th>\n",
1739
+ " <th>A</th>\n",
1740
+ " <th>B</th>\n",
1741
+ " <th>A</th>\n",
1742
+ " <th>B</th>\n",
1743
+ " </tr>\n",
1744
+ " </thead>\n",
1745
+ " <tbody>\n",
1746
+ " <tr>\n",
1747
+ " <th>1</th>\n",
1748
+ " <td>A1</td>\n",
1749
+ " <td>B1</td>\n",
1750
+ " <td>NaN</td>\n",
1751
+ " <td>NaN</td>\n",
1752
+ " </tr>\n",
1753
+ " <tr>\n",
1754
+ " <th>2</th>\n",
1755
+ " <td>A2</td>\n",
1756
+ " <td>B2</td>\n",
1757
+ " <td>NaN</td>\n",
1758
+ " <td>NaN</td>\n",
1759
+ " </tr>\n",
1760
+ " <tr>\n",
1761
+ " <th>3</th>\n",
1762
+ " <td>NaN</td>\n",
1763
+ " <td>NaN</td>\n",
1764
+ " <td>A3</td>\n",
1765
+ " <td>B3</td>\n",
1766
+ " </tr>\n",
1767
+ " <tr>\n",
1768
+ " <th>4</th>\n",
1769
+ " <td>NaN</td>\n",
1770
+ " <td>NaN</td>\n",
1771
+ " <td>A4</td>\n",
1772
+ " <td>B4</td>\n",
1773
+ " </tr>\n",
1774
+ " </tbody>\n",
1775
+ "</table>\n",
1776
+ "</div>"
1777
+ ],
1778
+ "text/plain": [
1779
+ " A B A B\n",
1780
+ "1 A1 B1 NaN NaN\n",
1781
+ "2 A2 B2 NaN NaN\n",
1782
+ "3 NaN NaN A3 B3\n",
1783
+ "4 NaN NaN A4 B4"
1784
+ ]
1785
+ },
1786
+ "execution_count": 63,
1787
+ "metadata": {},
1788
+ "output_type": "execute_result"
1789
+ }
1790
+ ],
1791
+ "source": [
1792
+ "pd.concat([df1, df2], axis=1)"
1793
+ ]
1794
+ },
1795
+ {
1796
+ "cell_type": "code",
1797
+ "execution_count": 64,
1798
+ "metadata": {
1799
+ "collapsed": true
1800
+ },
1801
+ "outputs": [],
1802
+ "source": [
1803
+ "def make_df(cols,index):\n",
1804
+ " data={c:[str(c)+str(i) for i in index] for c in cols}\n",
1805
+ " return pd.DataFrame(data,index=index)\n",
1806
+ "df1=make_df('AB',[1,2])\n",
1807
+ "df2=make_df('AB',[1,2])"
1808
+ ]
1809
+ },
1810
+ {
1811
+ "cell_type": "code",
1812
+ "execution_count": 65,
1813
+ "metadata": {},
1814
+ "outputs": [
1815
+ {
1816
+ "data": {
1817
+ "text/html": [
1818
+ "<div>\n",
1819
+ "<style>\n",
1820
+ " .dataframe thead tr:only-child th {\n",
1821
+ " text-align: right;\n",
1822
+ " }\n",
1823
+ "\n",
1824
+ " .dataframe thead th {\n",
1825
+ " text-align: left;\n",
1826
+ " }\n",
1827
+ "\n",
1828
+ " .dataframe tbody tr th {\n",
1829
+ " vertical-align: top;\n",
1830
+ " }\n",
1831
+ "</style>\n",
1832
+ "<table border=\"1\" class=\"dataframe\">\n",
1833
+ " <thead>\n",
1834
+ " <tr style=\"text-align: right;\">\n",
1835
+ " <th></th>\n",
1836
+ " <th>A</th>\n",
1837
+ " <th>B</th>\n",
1838
+ " </tr>\n",
1839
+ " </thead>\n",
1840
+ " <tbody>\n",
1841
+ " <tr>\n",
1842
+ " <th>1</th>\n",
1843
+ " <td>A1</td>\n",
1844
+ " <td>B1</td>\n",
1845
+ " </tr>\n",
1846
+ " <tr>\n",
1847
+ " <th>2</th>\n",
1848
+ " <td>A2</td>\n",
1849
+ " <td>B2</td>\n",
1850
+ " </tr>\n",
1851
+ " <tr>\n",
1852
+ " <th>1</th>\n",
1853
+ " <td>A1</td>\n",
1854
+ " <td>B1</td>\n",
1855
+ " </tr>\n",
1856
+ " <tr>\n",
1857
+ " <th>2</th>\n",
1858
+ " <td>A2</td>\n",
1859
+ " <td>B2</td>\n",
1860
+ " </tr>\n",
1861
+ " </tbody>\n",
1862
+ "</table>\n",
1863
+ "</div>"
1864
+ ],
1865
+ "text/plain": [
1866
+ " A B\n",
1867
+ "1 A1 B1\n",
1868
+ "2 A2 B2\n",
1869
+ "1 A1 B1\n",
1870
+ "2 A2 B2"
1871
+ ]
1872
+ },
1873
+ "execution_count": 65,
1874
+ "metadata": {},
1875
+ "output_type": "execute_result"
1876
+ }
1877
+ ],
1878
+ "source": [
1879
+ "pd.concat([df1,df2])"
1880
+ ]
1881
+ },
1882
+ {
1883
+ "cell_type": "code",
1884
+ "execution_count": 69,
1885
+ "metadata": {},
1886
+ "outputs": [
1887
+ {
1888
+ "data": {
1889
+ "text/html": [
1890
+ "<div>\n",
1891
+ "<style>\n",
1892
+ " .dataframe thead tr:only-child th {\n",
1893
+ " text-align: right;\n",
1894
+ " }\n",
1895
+ "\n",
1896
+ " .dataframe thead th {\n",
1897
+ " text-align: left;\n",
1898
+ " }\n",
1899
+ "\n",
1900
+ " .dataframe tbody tr th {\n",
1901
+ " vertical-align: top;\n",
1902
+ " }\n",
1903
+ "</style>\n",
1904
+ "<table border=\"1\" class=\"dataframe\">\n",
1905
+ " <thead>\n",
1906
+ " <tr style=\"text-align: right;\">\n",
1907
+ " <th></th>\n",
1908
+ " <th>A</th>\n",
1909
+ " <th>B</th>\n",
1910
+ " </tr>\n",
1911
+ " </thead>\n",
1912
+ " <tbody>\n",
1913
+ " <tr>\n",
1914
+ " <th>0</th>\n",
1915
+ " <td>A1</td>\n",
1916
+ " <td>B1</td>\n",
1917
+ " </tr>\n",
1918
+ " <tr>\n",
1919
+ " <th>1</th>\n",
1920
+ " <td>A2</td>\n",
1921
+ " <td>B2</td>\n",
1922
+ " </tr>\n",
1923
+ " <tr>\n",
1924
+ " <th>2</th>\n",
1925
+ " <td>A1</td>\n",
1926
+ " <td>B1</td>\n",
1927
+ " </tr>\n",
1928
+ " <tr>\n",
1929
+ " <th>3</th>\n",
1930
+ " <td>A2</td>\n",
1931
+ " <td>B2</td>\n",
1932
+ " </tr>\n",
1933
+ " </tbody>\n",
1934
+ "</table>\n",
1935
+ "</div>"
1936
+ ],
1937
+ "text/plain": [
1938
+ " A B\n",
1939
+ "0 A1 B1\n",
1940
+ "1 A2 B2\n",
1941
+ "2 A1 B1\n",
1942
+ "3 A2 B2"
1943
+ ]
1944
+ },
1945
+ "execution_count": 69,
1946
+ "metadata": {},
1947
+ "output_type": "execute_result"
1948
+ }
1949
+ ],
1950
+ "source": [
1951
+ "pd.concat([df1,df2], ignore_index=True)"
1952
+ ]
1953
+ },
1954
+ {
1955
+ "cell_type": "code",
1956
+ "execution_count": 76,
1957
+ "metadata": {},
1958
+ "outputs": [
1959
+ {
1960
+ "data": {
1961
+ "text/html": [
1962
+ "<div>\n",
1963
+ "<style>\n",
1964
+ " .dataframe thead tr:only-child th {\n",
1965
+ " text-align: right;\n",
1966
+ " }\n",
1967
+ "\n",
1968
+ " .dataframe thead th {\n",
1969
+ " text-align: left;\n",
1970
+ " }\n",
1971
+ "\n",
1972
+ " .dataframe tbody tr th {\n",
1973
+ " vertical-align: top;\n",
1974
+ " }\n",
1975
+ "</style>\n",
1976
+ "<table border=\"1\" class=\"dataframe\">\n",
1977
+ " <thead>\n",
1978
+ " <tr style=\"text-align: right;\">\n",
1979
+ " <th></th>\n",
1980
+ " <th></th>\n",
1981
+ " <th>A</th>\n",
1982
+ " <th>B</th>\n",
1983
+ " </tr>\n",
1984
+ " </thead>\n",
1985
+ " <tbody>\n",
1986
+ " <tr>\n",
1987
+ " <th rowspan=\"2\" valign=\"top\">df1</th>\n",
1988
+ " <th>1</th>\n",
1989
+ " <td>A1</td>\n",
1990
+ " <td>B1</td>\n",
1991
+ " </tr>\n",
1992
+ " <tr>\n",
1993
+ " <th>2</th>\n",
1994
+ " <td>A2</td>\n",
1995
+ " <td>B2</td>\n",
1996
+ " </tr>\n",
1997
+ " <tr>\n",
1998
+ " <th rowspan=\"2\" valign=\"top\">df2</th>\n",
1999
+ " <th>1</th>\n",
2000
+ " <td>A1</td>\n",
2001
+ " <td>B1</td>\n",
2002
+ " </tr>\n",
2003
+ " <tr>\n",
2004
+ " <th>2</th>\n",
2005
+ " <td>A2</td>\n",
2006
+ " <td>B2</td>\n",
2007
+ " </tr>\n",
2008
+ " </tbody>\n",
2009
+ "</table>\n",
2010
+ "</div>"
2011
+ ],
2012
+ "text/plain": [
2013
+ " A B\n",
2014
+ "df1 1 A1 B1\n",
2015
+ " 2 A2 B2\n",
2016
+ "df2 1 A1 B1\n",
2017
+ " 2 A2 B2"
2018
+ ]
2019
+ },
2020
+ "execution_count": 76,
2021
+ "metadata": {},
2022
+ "output_type": "execute_result"
2023
+ }
2024
+ ],
2025
+ "source": [
2026
+ "pd.concat([df1,df2],keys=['df1', 'df2'])"
2027
+ ]
2028
+ },
2029
+ {
2030
+ "cell_type": "code",
2031
+ "execution_count": 71,
2032
+ "metadata": {
2033
+ "collapsed": true
2034
+ },
2035
+ "outputs": [],
2036
+ "source": [
2037
+ "a=make_df('ABC',[1,2])\n",
2038
+ "b=make_df('BCD',[3,4])"
2039
+ ]
2040
+ },
2041
+ {
2042
+ "cell_type": "code",
2043
+ "execution_count": 72,
2044
+ "metadata": {},
2045
+ "outputs": [
2046
+ {
2047
+ "data": {
2048
+ "text/html": [
2049
+ "<div>\n",
2050
+ "<style>\n",
2051
+ " .dataframe thead tr:only-child th {\n",
2052
+ " text-align: right;\n",
2053
+ " }\n",
2054
+ "\n",
2055
+ " .dataframe thead th {\n",
2056
+ " text-align: left;\n",
2057
+ " }\n",
2058
+ "\n",
2059
+ " .dataframe tbody tr th {\n",
2060
+ " vertical-align: top;\n",
2061
+ " }\n",
2062
+ "</style>\n",
2063
+ "<table border=\"1\" class=\"dataframe\">\n",
2064
+ " <thead>\n",
2065
+ " <tr style=\"text-align: right;\">\n",
2066
+ " <th></th>\n",
2067
+ " <th>A</th>\n",
2068
+ " <th>B</th>\n",
2069
+ " <th>C</th>\n",
2070
+ " </tr>\n",
2071
+ " </thead>\n",
2072
+ " <tbody>\n",
2073
+ " <tr>\n",
2074
+ " <th>1</th>\n",
2075
+ " <td>A1</td>\n",
2076
+ " <td>B1</td>\n",
2077
+ " <td>C1</td>\n",
2078
+ " </tr>\n",
2079
+ " <tr>\n",
2080
+ " <th>2</th>\n",
2081
+ " <td>A2</td>\n",
2082
+ " <td>B2</td>\n",
2083
+ " <td>C2</td>\n",
2084
+ " </tr>\n",
2085
+ " </tbody>\n",
2086
+ "</table>\n",
2087
+ "</div>"
2088
+ ],
2089
+ "text/plain": [
2090
+ " A B C\n",
2091
+ "1 A1 B1 C1\n",
2092
+ "2 A2 B2 C2"
2093
+ ]
2094
+ },
2095
+ "execution_count": 72,
2096
+ "metadata": {},
2097
+ "output_type": "execute_result"
2098
+ }
2099
+ ],
2100
+ "source": [
2101
+ "a"
2102
+ ]
2103
+ },
2104
+ {
2105
+ "cell_type": "code",
2106
+ "execution_count": 73,
2107
+ "metadata": {},
2108
+ "outputs": [
2109
+ {
2110
+ "data": {
2111
+ "text/html": [
2112
+ "<div>\n",
2113
+ "<style>\n",
2114
+ " .dataframe thead tr:only-child th {\n",
2115
+ " text-align: right;\n",
2116
+ " }\n",
2117
+ "\n",
2118
+ " .dataframe thead th {\n",
2119
+ " text-align: left;\n",
2120
+ " }\n",
2121
+ "\n",
2122
+ " .dataframe tbody tr th {\n",
2123
+ " vertical-align: top;\n",
2124
+ " }\n",
2125
+ "</style>\n",
2126
+ "<table border=\"1\" class=\"dataframe\">\n",
2127
+ " <thead>\n",
2128
+ " <tr style=\"text-align: right;\">\n",
2129
+ " <th></th>\n",
2130
+ " <th>B</th>\n",
2131
+ " <th>C</th>\n",
2132
+ " <th>D</th>\n",
2133
+ " </tr>\n",
2134
+ " </thead>\n",
2135
+ " <tbody>\n",
2136
+ " <tr>\n",
2137
+ " <th>3</th>\n",
2138
+ " <td>B3</td>\n",
2139
+ " <td>C3</td>\n",
2140
+ " <td>D3</td>\n",
2141
+ " </tr>\n",
2142
+ " <tr>\n",
2143
+ " <th>4</th>\n",
2144
+ " <td>B4</td>\n",
2145
+ " <td>C4</td>\n",
2146
+ " <td>D4</td>\n",
2147
+ " </tr>\n",
2148
+ " </tbody>\n",
2149
+ "</table>\n",
2150
+ "</div>"
2151
+ ],
2152
+ "text/plain": [
2153
+ " B C D\n",
2154
+ "3 B3 C3 D3\n",
2155
+ "4 B4 C4 D4"
2156
+ ]
2157
+ },
2158
+ "execution_count": 73,
2159
+ "metadata": {},
2160
+ "output_type": "execute_result"
2161
+ }
2162
+ ],
2163
+ "source": [
2164
+ "b"
2165
+ ]
2166
+ },
2167
+ {
2168
+ "cell_type": "code",
2169
+ "execution_count": 74,
2170
+ "metadata": {},
2171
+ "outputs": [
2172
+ {
2173
+ "data": {
2174
+ "text/html": [
2175
+ "<div>\n",
2176
+ "<style>\n",
2177
+ " .dataframe thead tr:only-child th {\n",
2178
+ " text-align: right;\n",
2179
+ " }\n",
2180
+ "\n",
2181
+ " .dataframe thead th {\n",
2182
+ " text-align: left;\n",
2183
+ " }\n",
2184
+ "\n",
2185
+ " .dataframe tbody tr th {\n",
2186
+ " vertical-align: top;\n",
2187
+ " }\n",
2188
+ "</style>\n",
2189
+ "<table border=\"1\" class=\"dataframe\">\n",
2190
+ " <thead>\n",
2191
+ " <tr style=\"text-align: right;\">\n",
2192
+ " <th></th>\n",
2193
+ " <th>B</th>\n",
2194
+ " <th>C</th>\n",
2195
+ " </tr>\n",
2196
+ " </thead>\n",
2197
+ " <tbody>\n",
2198
+ " <tr>\n",
2199
+ " <th>1</th>\n",
2200
+ " <td>B1</td>\n",
2201
+ " <td>C1</td>\n",
2202
+ " </tr>\n",
2203
+ " <tr>\n",
2204
+ " <th>2</th>\n",
2205
+ " <td>B2</td>\n",
2206
+ " <td>C2</td>\n",
2207
+ " </tr>\n",
2208
+ " <tr>\n",
2209
+ " <th>3</th>\n",
2210
+ " <td>B3</td>\n",
2211
+ " <td>C3</td>\n",
2212
+ " </tr>\n",
2213
+ " <tr>\n",
2214
+ " <th>4</th>\n",
2215
+ " <td>B4</td>\n",
2216
+ " <td>C4</td>\n",
2217
+ " </tr>\n",
2218
+ " </tbody>\n",
2219
+ "</table>\n",
2220
+ "</div>"
2221
+ ],
2222
+ "text/plain": [
2223
+ " B C\n",
2224
+ "1 B1 C1\n",
2225
+ "2 B2 C2\n",
2226
+ "3 B3 C3\n",
2227
+ "4 B4 C4"
2228
+ ]
2229
+ },
2230
+ "execution_count": 74,
2231
+ "metadata": {},
2232
+ "output_type": "execute_result"
2233
+ }
2234
+ ],
2235
+ "source": [
2236
+ "pd.concat([a,b],join='inner')"
2237
+ ]
2238
+ },
2239
+ {
2240
+ "cell_type": "code",
2241
+ "execution_count": 77,
2242
+ "metadata": {
2243
+ "collapsed": true
2244
+ },
2245
+ "outputs": [],
2246
+ "source": [
2247
+ "left=pd.DataFrame({'key':['k0','k1','k2','k3'],\n",
2248
+ " 'A':['A0','A1','A2','A3'],\n",
2249
+ " 'B':['B0','B1','B2','B3'],\n",
2250
+ " })\n",
2251
+ "right=pd.DataFrame({'key':['k0','k1','k4','k3'],\n",
2252
+ " 'C':['C0','C1','C2','C3'],\n",
2253
+ " 'D':['D0','D1','D2','D3'],\n",
2254
+ " })"
2255
+ ]
2256
+ },
2257
+ {
2258
+ "cell_type": "code",
2259
+ "execution_count": 78,
2260
+ "metadata": {},
2261
+ "outputs": [
2262
+ {
2263
+ "data": {
2264
+ "text/html": [
2265
+ "<div>\n",
2266
+ "<style>\n",
2267
+ " .dataframe thead tr:only-child th {\n",
2268
+ " text-align: right;\n",
2269
+ " }\n",
2270
+ "\n",
2271
+ " .dataframe thead th {\n",
2272
+ " text-align: left;\n",
2273
+ " }\n",
2274
+ "\n",
2275
+ " .dataframe tbody tr th {\n",
2276
+ " vertical-align: top;\n",
2277
+ " }\n",
2278
+ "</style>\n",
2279
+ "<table border=\"1\" class=\"dataframe\">\n",
2280
+ " <thead>\n",
2281
+ " <tr style=\"text-align: right;\">\n",
2282
+ " <th></th>\n",
2283
+ " <th>A</th>\n",
2284
+ " <th>B</th>\n",
2285
+ " <th>key</th>\n",
2286
+ " </tr>\n",
2287
+ " </thead>\n",
2288
+ " <tbody>\n",
2289
+ " <tr>\n",
2290
+ " <th>0</th>\n",
2291
+ " <td>A0</td>\n",
2292
+ " <td>B0</td>\n",
2293
+ " <td>k0</td>\n",
2294
+ " </tr>\n",
2295
+ " <tr>\n",
2296
+ " <th>1</th>\n",
2297
+ " <td>A1</td>\n",
2298
+ " <td>B1</td>\n",
2299
+ " <td>k1</td>\n",
2300
+ " </tr>\n",
2301
+ " <tr>\n",
2302
+ " <th>2</th>\n",
2303
+ " <td>A2</td>\n",
2304
+ " <td>B2</td>\n",
2305
+ " <td>k2</td>\n",
2306
+ " </tr>\n",
2307
+ " <tr>\n",
2308
+ " <th>3</th>\n",
2309
+ " <td>A3</td>\n",
2310
+ " <td>B3</td>\n",
2311
+ " <td>k3</td>\n",
2312
+ " </tr>\n",
2313
+ " </tbody>\n",
2314
+ "</table>\n",
2315
+ "</div>"
2316
+ ],
2317
+ "text/plain": [
2318
+ " A B key\n",
2319
+ "0 A0 B0 k0\n",
2320
+ "1 A1 B1 k1\n",
2321
+ "2 A2 B2 k2\n",
2322
+ "3 A3 B3 k3"
2323
+ ]
2324
+ },
2325
+ "execution_count": 78,
2326
+ "metadata": {},
2327
+ "output_type": "execute_result"
2328
+ }
2329
+ ],
2330
+ "source": [
2331
+ "left"
2332
+ ]
2333
+ },
2334
+ {
2335
+ "cell_type": "code",
2336
+ "execution_count": 79,
2337
+ "metadata": {},
2338
+ "outputs": [
2339
+ {
2340
+ "data": {
2341
+ "text/html": [
2342
+ "<div>\n",
2343
+ "<style>\n",
2344
+ " .dataframe thead tr:only-child th {\n",
2345
+ " text-align: right;\n",
2346
+ " }\n",
2347
+ "\n",
2348
+ " .dataframe thead th {\n",
2349
+ " text-align: left;\n",
2350
+ " }\n",
2351
+ "\n",
2352
+ " .dataframe tbody tr th {\n",
2353
+ " vertical-align: top;\n",
2354
+ " }\n",
2355
+ "</style>\n",
2356
+ "<table border=\"1\" class=\"dataframe\">\n",
2357
+ " <thead>\n",
2358
+ " <tr style=\"text-align: right;\">\n",
2359
+ " <th></th>\n",
2360
+ " <th>C</th>\n",
2361
+ " <th>D</th>\n",
2362
+ " <th>key</th>\n",
2363
+ " </tr>\n",
2364
+ " </thead>\n",
2365
+ " <tbody>\n",
2366
+ " <tr>\n",
2367
+ " <th>0</th>\n",
2368
+ " <td>C0</td>\n",
2369
+ " <td>D0</td>\n",
2370
+ " <td>k0</td>\n",
2371
+ " </tr>\n",
2372
+ " <tr>\n",
2373
+ " <th>1</th>\n",
2374
+ " <td>C1</td>\n",
2375
+ " <td>D1</td>\n",
2376
+ " <td>k1</td>\n",
2377
+ " </tr>\n",
2378
+ " <tr>\n",
2379
+ " <th>2</th>\n",
2380
+ " <td>C2</td>\n",
2381
+ " <td>D2</td>\n",
2382
+ " <td>k4</td>\n",
2383
+ " </tr>\n",
2384
+ " <tr>\n",
2385
+ " <th>3</th>\n",
2386
+ " <td>C3</td>\n",
2387
+ " <td>D3</td>\n",
2388
+ " <td>k3</td>\n",
2389
+ " </tr>\n",
2390
+ " </tbody>\n",
2391
+ "</table>\n",
2392
+ "</div>"
2393
+ ],
2394
+ "text/plain": [
2395
+ " C D key\n",
2396
+ "0 C0 D0 k0\n",
2397
+ "1 C1 D1 k1\n",
2398
+ "2 C2 D2 k4\n",
2399
+ "3 C3 D3 k3"
2400
+ ]
2401
+ },
2402
+ "execution_count": 79,
2403
+ "metadata": {},
2404
+ "output_type": "execute_result"
2405
+ }
2406
+ ],
2407
+ "source": [
2408
+ "right"
2409
+ ]
2410
+ },
2411
+ {
2412
+ "cell_type": "code",
2413
+ "execution_count": 81,
2414
+ "metadata": {},
2415
+ "outputs": [
2416
+ {
2417
+ "data": {
2418
+ "text/html": [
2419
+ "<div>\n",
2420
+ "<style>\n",
2421
+ " .dataframe thead tr:only-child th {\n",
2422
+ " text-align: right;\n",
2423
+ " }\n",
2424
+ "\n",
2425
+ " .dataframe thead th {\n",
2426
+ " text-align: left;\n",
2427
+ " }\n",
2428
+ "\n",
2429
+ " .dataframe tbody tr th {\n",
2430
+ " vertical-align: top;\n",
2431
+ " }\n",
2432
+ "</style>\n",
2433
+ "<table border=\"1\" class=\"dataframe\">\n",
2434
+ " <thead>\n",
2435
+ " <tr style=\"text-align: right;\">\n",
2436
+ " <th></th>\n",
2437
+ " <th>A</th>\n",
2438
+ " <th>B</th>\n",
2439
+ " <th>key</th>\n",
2440
+ " <th>C</th>\n",
2441
+ " <th>D</th>\n",
2442
+ " </tr>\n",
2443
+ " </thead>\n",
2444
+ " <tbody>\n",
2445
+ " <tr>\n",
2446
+ " <th>0</th>\n",
2447
+ " <td>A0</td>\n",
2448
+ " <td>B0</td>\n",
2449
+ " <td>k0</td>\n",
2450
+ " <td>C0</td>\n",
2451
+ " <td>D0</td>\n",
2452
+ " </tr>\n",
2453
+ " <tr>\n",
2454
+ " <th>1</th>\n",
2455
+ " <td>A1</td>\n",
2456
+ " <td>B1</td>\n",
2457
+ " <td>k1</td>\n",
2458
+ " <td>C1</td>\n",
2459
+ " <td>D1</td>\n",
2460
+ " </tr>\n",
2461
+ " <tr>\n",
2462
+ " <th>2</th>\n",
2463
+ " <td>A3</td>\n",
2464
+ " <td>B3</td>\n",
2465
+ " <td>k3</td>\n",
2466
+ " <td>C3</td>\n",
2467
+ " <td>D3</td>\n",
2468
+ " </tr>\n",
2469
+ " </tbody>\n",
2470
+ "</table>\n",
2471
+ "</div>"
2472
+ ],
2473
+ "text/plain": [
2474
+ " A B key C D\n",
2475
+ "0 A0 B0 k0 C0 D0\n",
2476
+ "1 A1 B1 k1 C1 D1\n",
2477
+ "2 A3 B3 k3 C3 D3"
2478
+ ]
2479
+ },
2480
+ "execution_count": 81,
2481
+ "metadata": {},
2482
+ "output_type": "execute_result"
2483
+ }
2484
+ ],
2485
+ "source": [
2486
+ "pd.merge(left, right)"
2487
+ ]
2488
+ },
2489
+ {
2490
+ "cell_type": "code",
2491
+ "execution_count": 82,
2492
+ "metadata": {},
2493
+ "outputs": [
2494
+ {
2495
+ "data": {
2496
+ "text/html": [
2497
+ "<div>\n",
2498
+ "<style>\n",
2499
+ " .dataframe thead tr:only-child th {\n",
2500
+ " text-align: right;\n",
2501
+ " }\n",
2502
+ "\n",
2503
+ " .dataframe thead th {\n",
2504
+ " text-align: left;\n",
2505
+ " }\n",
2506
+ "\n",
2507
+ " .dataframe tbody tr th {\n",
2508
+ " vertical-align: top;\n",
2509
+ " }\n",
2510
+ "</style>\n",
2511
+ "<table border=\"1\" class=\"dataframe\">\n",
2512
+ " <thead>\n",
2513
+ " <tr style=\"text-align: right;\">\n",
2514
+ " <th></th>\n",
2515
+ " <th>A</th>\n",
2516
+ " <th>B</th>\n",
2517
+ " <th>key</th>\n",
2518
+ " <th>C</th>\n",
2519
+ " <th>D</th>\n",
2520
+ " </tr>\n",
2521
+ " </thead>\n",
2522
+ " <tbody>\n",
2523
+ " <tr>\n",
2524
+ " <th>0</th>\n",
2525
+ " <td>A0</td>\n",
2526
+ " <td>B0</td>\n",
2527
+ " <td>k0</td>\n",
2528
+ " <td>C0</td>\n",
2529
+ " <td>D0</td>\n",
2530
+ " </tr>\n",
2531
+ " <tr>\n",
2532
+ " <th>1</th>\n",
2533
+ " <td>A1</td>\n",
2534
+ " <td>B1</td>\n",
2535
+ " <td>k1</td>\n",
2536
+ " <td>C1</td>\n",
2537
+ " <td>D1</td>\n",
2538
+ " </tr>\n",
2539
+ " <tr>\n",
2540
+ " <th>2</th>\n",
2541
+ " <td>A2</td>\n",
2542
+ " <td>B2</td>\n",
2543
+ " <td>k2</td>\n",
2544
+ " <td>NaN</td>\n",
2545
+ " <td>NaN</td>\n",
2546
+ " </tr>\n",
2547
+ " <tr>\n",
2548
+ " <th>3</th>\n",
2549
+ " <td>A3</td>\n",
2550
+ " <td>B3</td>\n",
2551
+ " <td>k3</td>\n",
2552
+ " <td>C3</td>\n",
2553
+ " <td>D3</td>\n",
2554
+ " </tr>\n",
2555
+ " <tr>\n",
2556
+ " <th>4</th>\n",
2557
+ " <td>NaN</td>\n",
2558
+ " <td>NaN</td>\n",
2559
+ " <td>k4</td>\n",
2560
+ " <td>C2</td>\n",
2561
+ " <td>D2</td>\n",
2562
+ " </tr>\n",
2563
+ " </tbody>\n",
2564
+ "</table>\n",
2565
+ "</div>"
2566
+ ],
2567
+ "text/plain": [
2568
+ " A B key C D\n",
2569
+ "0 A0 B0 k0 C0 D0\n",
2570
+ "1 A1 B1 k1 C1 D1\n",
2571
+ "2 A2 B2 k2 NaN NaN\n",
2572
+ "3 A3 B3 k3 C3 D3\n",
2573
+ "4 NaN NaN k4 C2 D2"
2574
+ ]
2575
+ },
2576
+ "execution_count": 82,
2577
+ "metadata": {},
2578
+ "output_type": "execute_result"
2579
+ }
2580
+ ],
2581
+ "source": [
2582
+ "pd.merge(left, right, how='outer')"
2583
+ ]
2584
+ },
2585
+ {
2586
+ "cell_type": "code",
2587
+ "execution_count": 83,
2588
+ "metadata": {},
2589
+ "outputs": [
2590
+ {
2591
+ "data": {
2592
+ "text/html": [
2593
+ "<div>\n",
2594
+ "<style>\n",
2595
+ " .dataframe thead tr:only-child th {\n",
2596
+ " text-align: right;\n",
2597
+ " }\n",
2598
+ "\n",
2599
+ " .dataframe thead th {\n",
2600
+ " text-align: left;\n",
2601
+ " }\n",
2602
+ "\n",
2603
+ " .dataframe tbody tr th {\n",
2604
+ " vertical-align: top;\n",
2605
+ " }\n",
2606
+ "</style>\n",
2607
+ "<table border=\"1\" class=\"dataframe\">\n",
2608
+ " <thead>\n",
2609
+ " <tr style=\"text-align: right;\">\n",
2610
+ " <th></th>\n",
2611
+ " <th>A</th>\n",
2612
+ " <th>B</th>\n",
2613
+ " <th>key</th>\n",
2614
+ " <th>C</th>\n",
2615
+ " <th>D</th>\n",
2616
+ " </tr>\n",
2617
+ " </thead>\n",
2618
+ " <tbody>\n",
2619
+ " <tr>\n",
2620
+ " <th>0</th>\n",
2621
+ " <td>A0</td>\n",
2622
+ " <td>B0</td>\n",
2623
+ " <td>k0</td>\n",
2624
+ " <td>C0</td>\n",
2625
+ " <td>D0</td>\n",
2626
+ " </tr>\n",
2627
+ " <tr>\n",
2628
+ " <th>1</th>\n",
2629
+ " <td>A1</td>\n",
2630
+ " <td>B1</td>\n",
2631
+ " <td>k1</td>\n",
2632
+ " <td>C1</td>\n",
2633
+ " <td>D1</td>\n",
2634
+ " </tr>\n",
2635
+ " <tr>\n",
2636
+ " <th>2</th>\n",
2637
+ " <td>A2</td>\n",
2638
+ " <td>B2</td>\n",
2639
+ " <td>k2</td>\n",
2640
+ " <td>NaN</td>\n",
2641
+ " <td>NaN</td>\n",
2642
+ " </tr>\n",
2643
+ " <tr>\n",
2644
+ " <th>3</th>\n",
2645
+ " <td>A3</td>\n",
2646
+ " <td>B3</td>\n",
2647
+ " <td>k3</td>\n",
2648
+ " <td>C3</td>\n",
2649
+ " <td>D3</td>\n",
2650
+ " </tr>\n",
2651
+ " </tbody>\n",
2652
+ "</table>\n",
2653
+ "</div>"
2654
+ ],
2655
+ "text/plain": [
2656
+ " A B key C D\n",
2657
+ "0 A0 B0 k0 C0 D0\n",
2658
+ "1 A1 B1 k1 C1 D1\n",
2659
+ "2 A2 B2 k2 NaN NaN\n",
2660
+ "3 A3 B3 k3 C3 D3"
2661
+ ]
2662
+ },
2663
+ "execution_count": 83,
2664
+ "metadata": {},
2665
+ "output_type": "execute_result"
2666
+ }
2667
+ ],
2668
+ "source": [
2669
+ "pd.merge(left, right, how='left')"
2670
+ ]
2671
+ },
2672
+ {
2673
+ "cell_type": "code",
2674
+ "execution_count": 84,
2675
+ "metadata": {},
2676
+ "outputs": [
2677
+ {
2678
+ "data": {
2679
+ "text/html": [
2680
+ "<div>\n",
2681
+ "<style>\n",
2682
+ " .dataframe thead tr:only-child th {\n",
2683
+ " text-align: right;\n",
2684
+ " }\n",
2685
+ "\n",
2686
+ " .dataframe thead th {\n",
2687
+ " text-align: left;\n",
2688
+ " }\n",
2689
+ "\n",
2690
+ " .dataframe tbody tr th {\n",
2691
+ " vertical-align: top;\n",
2692
+ " }\n",
2693
+ "</style>\n",
2694
+ "<table border=\"1\" class=\"dataframe\">\n",
2695
+ " <thead>\n",
2696
+ " <tr style=\"text-align: right;\">\n",
2697
+ " <th></th>\n",
2698
+ " <th>A</th>\n",
2699
+ " <th>B</th>\n",
2700
+ " <th>key</th>\n",
2701
+ " <th>C</th>\n",
2702
+ " <th>D</th>\n",
2703
+ " </tr>\n",
2704
+ " </thead>\n",
2705
+ " <tbody>\n",
2706
+ " <tr>\n",
2707
+ " <th>0</th>\n",
2708
+ " <td>A0</td>\n",
2709
+ " <td>B0</td>\n",
2710
+ " <td>k0</td>\n",
2711
+ " <td>C0</td>\n",
2712
+ " <td>D0</td>\n",
2713
+ " </tr>\n",
2714
+ " <tr>\n",
2715
+ " <th>1</th>\n",
2716
+ " <td>A1</td>\n",
2717
+ " <td>B1</td>\n",
2718
+ " <td>k1</td>\n",
2719
+ " <td>C1</td>\n",
2720
+ " <td>D1</td>\n",
2721
+ " </tr>\n",
2722
+ " <tr>\n",
2723
+ " <th>2</th>\n",
2724
+ " <td>A3</td>\n",
2725
+ " <td>B3</td>\n",
2726
+ " <td>k3</td>\n",
2727
+ " <td>C3</td>\n",
2728
+ " <td>D3</td>\n",
2729
+ " </tr>\n",
2730
+ " <tr>\n",
2731
+ " <th>3</th>\n",
2732
+ " <td>NaN</td>\n",
2733
+ " <td>NaN</td>\n",
2734
+ " <td>k4</td>\n",
2735
+ " <td>C2</td>\n",
2736
+ " <td>D2</td>\n",
2737
+ " </tr>\n",
2738
+ " </tbody>\n",
2739
+ "</table>\n",
2740
+ "</div>"
2741
+ ],
2742
+ "text/plain": [
2743
+ " A B key C D\n",
2744
+ "0 A0 B0 k0 C0 D0\n",
2745
+ "1 A1 B1 k1 C1 D1\n",
2746
+ "2 A3 B3 k3 C3 D3\n",
2747
+ "3 NaN NaN k4 C2 D2"
2748
+ ]
2749
+ },
2750
+ "execution_count": 84,
2751
+ "metadata": {},
2752
+ "output_type": "execute_result"
2753
+ }
2754
+ ],
2755
+ "source": [
2756
+ "pd.merge(left, right, how='right')"
2757
+ ]
2758
+ }
2759
+ ],
2760
+ "metadata": {
2761
+ "kernelspec": {
2762
+ "display_name": "Python 3",
2763
+ "language": "python",
2764
+ "name": "python3"
2765
+ },
2766
+ "language_info": {
2767
+ "codemirror_mode": {
2768
+ "name": "ipython",
2769
+ "version": 3
2770
+ },
2771
+ "file_extension": ".py",
2772
+ "mimetype": "text/x-python",
2773
+ "name": "python",
2774
+ "nbconvert_exporter": "python",
2775
+ "pygments_lexer": "ipython3",
2776
+ "version": "3.6.3"
2777
+ }
2778
+ },
2779
+ "nbformat": 4,
2780
+ "nbformat_minor": 2
2781
+ }
Python_matplotlib.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
Python_reshape_拼接.ipynb ADDED
@@ -0,0 +1,765 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {
7
+ "collapsed": true
8
+ },
9
+ "outputs": [],
10
+ "source": [
11
+ "import numpy as np"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": 7,
17
+ "metadata": {},
18
+ "outputs": [
19
+ {
20
+ "data": {
21
+ "text/plain": [
22
+ "array([[ 0, 1, 2],\n",
23
+ " [ 3, 4, 5],\n",
24
+ " [ 6, 7, 8],\n",
25
+ " [ 9, 10, 11]])"
26
+ ]
27
+ },
28
+ "execution_count": 7,
29
+ "metadata": {},
30
+ "output_type": "execute_result"
31
+ }
32
+ ],
33
+ "source": [
34
+ "arr = np.arange(12)\n",
35
+ "arr = arr.reshape(4,3)\n",
36
+ "arr"
37
+ ]
38
+ },
39
+ {
40
+ "cell_type": "code",
41
+ "execution_count": 9,
42
+ "metadata": {},
43
+ "outputs": [
44
+ {
45
+ "data": {
46
+ "text/plain": [
47
+ "array([3, 4, 5])"
48
+ ]
49
+ },
50
+ "execution_count": 9,
51
+ "metadata": {},
52
+ "output_type": "execute_result"
53
+ }
54
+ ],
55
+ "source": [
56
+ "arr[1]"
57
+ ]
58
+ },
59
+ {
60
+ "cell_type": "code",
61
+ "execution_count": 11,
62
+ "metadata": {},
63
+ "outputs": [
64
+ {
65
+ "data": {
66
+ "text/plain": [
67
+ "5"
68
+ ]
69
+ },
70
+ "execution_count": 11,
71
+ "metadata": {},
72
+ "output_type": "execute_result"
73
+ }
74
+ ],
75
+ "source": [
76
+ "arr[1][2]"
77
+ ]
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "execution_count": 16,
82
+ "metadata": {},
83
+ "outputs": [
84
+ {
85
+ "data": {
86
+ "text/plain": [
87
+ "array([[4, 5],\n",
88
+ " [7, 8]])"
89
+ ]
90
+ },
91
+ "execution_count": 16,
92
+ "metadata": {},
93
+ "output_type": "execute_result"
94
+ }
95
+ ],
96
+ "source": [
97
+ "temp = arr[1:3, 1:3]\n",
98
+ "temp"
99
+ ]
100
+ },
101
+ {
102
+ "cell_type": "code",
103
+ "execution_count": 19,
104
+ "metadata": {},
105
+ "outputs": [],
106
+ "source": [
107
+ "temp[1][1] = 9"
108
+ ]
109
+ },
110
+ {
111
+ "cell_type": "code",
112
+ "execution_count": 20,
113
+ "metadata": {},
114
+ "outputs": [
115
+ {
116
+ "data": {
117
+ "text/plain": [
118
+ "array([[4, 5],\n",
119
+ " [7, 9]])"
120
+ ]
121
+ },
122
+ "execution_count": 20,
123
+ "metadata": {},
124
+ "output_type": "execute_result"
125
+ }
126
+ ],
127
+ "source": [
128
+ "temp"
129
+ ]
130
+ },
131
+ {
132
+ "cell_type": "code",
133
+ "execution_count": 21,
134
+ "metadata": {},
135
+ "outputs": [
136
+ {
137
+ "data": {
138
+ "text/plain": [
139
+ "array([[ 0, 1, 2],\n",
140
+ " [ 3, 4, 5],\n",
141
+ " [ 6, 7, 9],\n",
142
+ " [ 9, 10, 11]])"
143
+ ]
144
+ },
145
+ "execution_count": 21,
146
+ "metadata": {},
147
+ "output_type": "execute_result"
148
+ }
149
+ ],
150
+ "source": [
151
+ "arr"
152
+ ]
153
+ },
154
+ {
155
+ "cell_type": "code",
156
+ "execution_count": 22,
157
+ "metadata": {},
158
+ "outputs": [
159
+ {
160
+ "data": {
161
+ "text/plain": [
162
+ "array([[ 0, 1, 2],\n",
163
+ " [ 3, 4, 5],\n",
164
+ " [ 6, 7, 8],\n",
165
+ " [ 9, 10, 11]])"
166
+ ]
167
+ },
168
+ "execution_count": 22,
169
+ "metadata": {},
170
+ "output_type": "execute_result"
171
+ }
172
+ ],
173
+ "source": [
174
+ "arr = np.arange(12)\n",
175
+ "arr = arr.reshape(4,3)\n",
176
+ "arr"
177
+ ]
178
+ },
179
+ {
180
+ "cell_type": "code",
181
+ "execution_count": 23,
182
+ "metadata": {},
183
+ "outputs": [
184
+ {
185
+ "data": {
186
+ "text/plain": [
187
+ "array([[4, 5],\n",
188
+ " [7, 8]])"
189
+ ]
190
+ },
191
+ "execution_count": 23,
192
+ "metadata": {},
193
+ "output_type": "execute_result"
194
+ }
195
+ ],
196
+ "source": [
197
+ "temp = np.copy(arr[1:3, 1:3])\n",
198
+ "temp"
199
+ ]
200
+ },
201
+ {
202
+ "cell_type": "code",
203
+ "execution_count": 24,
204
+ "metadata": {
205
+ "collapsed": true
206
+ },
207
+ "outputs": [],
208
+ "source": [
209
+ "temp[1][1] = 9"
210
+ ]
211
+ },
212
+ {
213
+ "cell_type": "code",
214
+ "execution_count": 25,
215
+ "metadata": {},
216
+ "outputs": [
217
+ {
218
+ "data": {
219
+ "text/plain": [
220
+ "array([[4, 5],\n",
221
+ " [7, 9]])"
222
+ ]
223
+ },
224
+ "execution_count": 25,
225
+ "metadata": {},
226
+ "output_type": "execute_result"
227
+ }
228
+ ],
229
+ "source": [
230
+ "temp"
231
+ ]
232
+ },
233
+ {
234
+ "cell_type": "code",
235
+ "execution_count": 26,
236
+ "metadata": {},
237
+ "outputs": [
238
+ {
239
+ "data": {
240
+ "text/plain": [
241
+ "array([[ 0, 1, 2],\n",
242
+ " [ 3, 4, 5],\n",
243
+ " [ 6, 7, 8],\n",
244
+ " [ 9, 10, 11]])"
245
+ ]
246
+ },
247
+ "execution_count": 26,
248
+ "metadata": {},
249
+ "output_type": "execute_result"
250
+ }
251
+ ],
252
+ "source": [
253
+ "arr"
254
+ ]
255
+ },
256
+ {
257
+ "cell_type": "code",
258
+ "execution_count": 34,
259
+ "metadata": {},
260
+ "outputs": [
261
+ {
262
+ "data": {
263
+ "text/plain": [
264
+ "array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])"
265
+ ]
266
+ },
267
+ "execution_count": 34,
268
+ "metadata": {},
269
+ "output_type": "execute_result"
270
+ }
271
+ ],
272
+ "source": [
273
+ "arr.reshape((2,3,2)).reshape((12,))"
274
+ ]
275
+ },
276
+ {
277
+ "cell_type": "code",
278
+ "execution_count": 35,
279
+ "metadata": {},
280
+ "outputs": [
281
+ {
282
+ "data": {
283
+ "text/plain": [
284
+ "array([[ 0, 1, 2],\n",
285
+ " [ 3, 4, 5],\n",
286
+ " [ 6, 7, 8],\n",
287
+ " [ 9, 10, 11]])"
288
+ ]
289
+ },
290
+ "execution_count": 35,
291
+ "metadata": {},
292
+ "output_type": "execute_result"
293
+ }
294
+ ],
295
+ "source": [
296
+ "arr"
297
+ ]
298
+ },
299
+ {
300
+ "cell_type": "code",
301
+ "execution_count": 36,
302
+ "metadata": {},
303
+ "outputs": [
304
+ {
305
+ "data": {
306
+ "text/plain": [
307
+ "array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])"
308
+ ]
309
+ },
310
+ "execution_count": 36,
311
+ "metadata": {},
312
+ "output_type": "execute_result"
313
+ }
314
+ ],
315
+ "source": [
316
+ "arr.ravel()"
317
+ ]
318
+ },
319
+ {
320
+ "cell_type": "code",
321
+ "execution_count": 37,
322
+ "metadata": {},
323
+ "outputs": [
324
+ {
325
+ "data": {
326
+ "text/plain": [
327
+ "array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])"
328
+ ]
329
+ },
330
+ "execution_count": 37,
331
+ "metadata": {},
332
+ "output_type": "execute_result"
333
+ }
334
+ ],
335
+ "source": [
336
+ "arr.flatten()"
337
+ ]
338
+ },
339
+ {
340
+ "cell_type": "code",
341
+ "execution_count": 38,
342
+ "metadata": {},
343
+ "outputs": [
344
+ {
345
+ "data": {
346
+ "text/plain": [
347
+ "array([[[ 0, 1],\n",
348
+ " [ 2, 3],\n",
349
+ " [ 4, 5]],\n",
350
+ "\n",
351
+ " [[ 6, 7],\n",
352
+ " [ 8, 9],\n",
353
+ " [10, 11]]])"
354
+ ]
355
+ },
356
+ "execution_count": 38,
357
+ "metadata": {},
358
+ "output_type": "execute_result"
359
+ }
360
+ ],
361
+ "source": [
362
+ "arr = arr.reshape((2,3,2))\n",
363
+ "arr"
364
+ ]
365
+ },
366
+ {
367
+ "cell_type": "code",
368
+ "execution_count": 39,
369
+ "metadata": {},
370
+ "outputs": [
371
+ {
372
+ "data": {
373
+ "text/plain": [
374
+ "array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])"
375
+ ]
376
+ },
377
+ "execution_count": 39,
378
+ "metadata": {},
379
+ "output_type": "execute_result"
380
+ }
381
+ ],
382
+ "source": [
383
+ "arr.ravel()"
384
+ ]
385
+ },
386
+ {
387
+ "cell_type": "code",
388
+ "execution_count": 40,
389
+ "metadata": {},
390
+ "outputs": [
391
+ {
392
+ "data": {
393
+ "text/plain": [
394
+ "array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])"
395
+ ]
396
+ },
397
+ "execution_count": 40,
398
+ "metadata": {},
399
+ "output_type": "execute_result"
400
+ }
401
+ ],
402
+ "source": [
403
+ "arr.flatten()"
404
+ ]
405
+ },
406
+ {
407
+ "cell_type": "code",
408
+ "execution_count": 49,
409
+ "metadata": {},
410
+ "outputs": [
411
+ {
412
+ "data": {
413
+ "text/plain": [
414
+ "array([[1, 2, 3],\n",
415
+ " [4, 5, 6]])"
416
+ ]
417
+ },
418
+ "execution_count": 49,
419
+ "metadata": {},
420
+ "output_type": "execute_result"
421
+ }
422
+ ],
423
+ "source": [
424
+ "a = np.array([[1,2,3],[4,5,6]])\n",
425
+ "a"
426
+ ]
427
+ },
428
+ {
429
+ "cell_type": "code",
430
+ "execution_count": 56,
431
+ "metadata": {},
432
+ "outputs": [
433
+ {
434
+ "data": {
435
+ "text/plain": [
436
+ "array([['a', 'b', 'c', 'm'],\n",
437
+ " ['d', 'e', 'f', 'n']], dtype='<U1')"
438
+ ]
439
+ },
440
+ "execution_count": 56,
441
+ "metadata": {},
442
+ "output_type": "execute_result"
443
+ }
444
+ ],
445
+ "source": [
446
+ "b = np.array([['a','b','c','m'],['d','e','f','n']])\n",
447
+ "b"
448
+ ]
449
+ },
450
+ {
451
+ "cell_type": "code",
452
+ "execution_count": 48,
453
+ "metadata": {},
454
+ "outputs": [
455
+ {
456
+ "data": {
457
+ "text/plain": [
458
+ "array([['1', '2', '3', 'a', 'b', 'c', 'm'],\n",
459
+ " ['4', '5', '6', 'd', 'e', 'f', 'n']], dtype='<U11')"
460
+ ]
461
+ },
462
+ "execution_count": 48,
463
+ "metadata": {},
464
+ "output_type": "execute_result"
465
+ }
466
+ ],
467
+ "source": [
468
+ "np.hstack([a,b])"
469
+ ]
470
+ },
471
+ {
472
+ "cell_type": "code",
473
+ "execution_count": 53,
474
+ "metadata": {},
475
+ "outputs": [
476
+ {
477
+ "data": {
478
+ "text/plain": [
479
+ "array([['1', '2', '3'],\n",
480
+ " ['4', '5', '6'],\n",
481
+ " ['a', 'b', 'c'],\n",
482
+ " ['d', 'e', 'f'],\n",
483
+ " ['m', 'n', 'q']], dtype='<U11')"
484
+ ]
485
+ },
486
+ "execution_count": 53,
487
+ "metadata": {},
488
+ "output_type": "execute_result"
489
+ }
490
+ ],
491
+ "source": [
492
+ "np.vstack([a,b])"
493
+ ]
494
+ },
495
+ {
496
+ "cell_type": "code",
497
+ "execution_count": 54,
498
+ "metadata": {},
499
+ "outputs": [
500
+ {
501
+ "data": {
502
+ "text/plain": [
503
+ "array([['1', '2', '3'],\n",
504
+ " ['4', '5', '6'],\n",
505
+ " ['a', 'b', 'c'],\n",
506
+ " ['d', 'e', 'f'],\n",
507
+ " ['m', 'n', 'q']], dtype='<U11')"
508
+ ]
509
+ },
510
+ "execution_count": 54,
511
+ "metadata": {},
512
+ "output_type": "execute_result"
513
+ }
514
+ ],
515
+ "source": [
516
+ "np.concatenate([a,b], axis=0)"
517
+ ]
518
+ },
519
+ {
520
+ "cell_type": "code",
521
+ "execution_count": 57,
522
+ "metadata": {},
523
+ "outputs": [
524
+ {
525
+ "data": {
526
+ "text/plain": [
527
+ "array([['1', '2', '3', 'a', 'b', 'c', 'm'],\n",
528
+ " ['4', '5', '6', 'd', 'e', 'f', 'n']], dtype='<U11')"
529
+ ]
530
+ },
531
+ "execution_count": 57,
532
+ "metadata": {},
533
+ "output_type": "execute_result"
534
+ }
535
+ ],
536
+ "source": [
537
+ "np.concatenate([a,b], axis=1)"
538
+ ]
539
+ },
540
+ {
541
+ "cell_type": "code",
542
+ "execution_count": 58,
543
+ "metadata": {},
544
+ "outputs": [
545
+ {
546
+ "data": {
547
+ "text/plain": [
548
+ "array([[[ 1, 2, 3],\n",
549
+ " [ 4, 5, 6],\n",
550
+ " [ 7, 8, 9],\n",
551
+ " [10, 11, 12]],\n",
552
+ "\n",
553
+ " [[13, 14, 15],\n",
554
+ " [16, 17, 18],\n",
555
+ " [19, 20, 21],\n",
556
+ " [22, 23, 24]],\n",
557
+ "\n",
558
+ " [[25, 26, 27],\n",
559
+ " [28, 29, 30],\n",
560
+ " [31, 32, 33],\n",
561
+ " [34, 35, 36]]])"
562
+ ]
563
+ },
564
+ "execution_count": 58,
565
+ "metadata": {},
566
+ "output_type": "execute_result"
567
+ }
568
+ ],
569
+ "source": [
570
+ "aa=np.arange(1,37).reshape(3,4,3)\n",
571
+ "aa"
572
+ ]
573
+ },
574
+ {
575
+ "cell_type": "code",
576
+ "execution_count": 59,
577
+ "metadata": {},
578
+ "outputs": [
579
+ {
580
+ "data": {
581
+ "text/plain": [
582
+ "array([[[101, 102, 103],\n",
583
+ " [104, 105, 106],\n",
584
+ " [107, 108, 109],\n",
585
+ " [110, 111, 112]],\n",
586
+ "\n",
587
+ " [[113, 114, 115],\n",
588
+ " [116, 117, 118],\n",
589
+ " [119, 120, 121],\n",
590
+ " [122, 123, 124]],\n",
591
+ "\n",
592
+ " [[125, 126, 127],\n",
593
+ " [128, 129, 130],\n",
594
+ " [131, 132, 133],\n",
595
+ " [134, 135, 136]]])"
596
+ ]
597
+ },
598
+ "execution_count": 59,
599
+ "metadata": {},
600
+ "output_type": "execute_result"
601
+ }
602
+ ],
603
+ "source": [
604
+ "bb=np.arange(101,137).reshape(3,4,3)\n",
605
+ "bb"
606
+ ]
607
+ },
608
+ {
609
+ "cell_type": "code",
610
+ "execution_count": 60,
611
+ "metadata": {},
612
+ "outputs": [
613
+ {
614
+ "data": {
615
+ "text/plain": [
616
+ "array([[[ 1, 2, 3],\n",
617
+ " [ 4, 5, 6],\n",
618
+ " [ 7, 8, 9],\n",
619
+ " [ 10, 11, 12]],\n",
620
+ "\n",
621
+ " [[ 13, 14, 15],\n",
622
+ " [ 16, 17, 18],\n",
623
+ " [ 19, 20, 21],\n",
624
+ " [ 22, 23, 24]],\n",
625
+ "\n",
626
+ " [[ 25, 26, 27],\n",
627
+ " [ 28, 29, 30],\n",
628
+ " [ 31, 32, 33],\n",
629
+ " [ 34, 35, 36]],\n",
630
+ "\n",
631
+ " [[101, 102, 103],\n",
632
+ " [104, 105, 106],\n",
633
+ " [107, 108, 109],\n",
634
+ " [110, 111, 112]],\n",
635
+ "\n",
636
+ " [[113, 114, 115],\n",
637
+ " [116, 117, 118],\n",
638
+ " [119, 120, 121],\n",
639
+ " [122, 123, 124]],\n",
640
+ "\n",
641
+ " [[125, 126, 127],\n",
642
+ " [128, 129, 130],\n",
643
+ " [131, 132, 133],\n",
644
+ " [134, 135, 136]]])"
645
+ ]
646
+ },
647
+ "execution_count": 60,
648
+ "metadata": {},
649
+ "output_type": "execute_result"
650
+ }
651
+ ],
652
+ "source": [
653
+ "np.concatenate([aa, bb], axis=0)"
654
+ ]
655
+ },
656
+ {
657
+ "cell_type": "code",
658
+ "execution_count": 61,
659
+ "metadata": {},
660
+ "outputs": [
661
+ {
662
+ "data": {
663
+ "text/plain": [
664
+ "array([[[ 1, 2, 3],\n",
665
+ " [ 4, 5, 6],\n",
666
+ " [ 7, 8, 9],\n",
667
+ " [ 10, 11, 12],\n",
668
+ " [101, 102, 103],\n",
669
+ " [104, 105, 106],\n",
670
+ " [107, 108, 109],\n",
671
+ " [110, 111, 112]],\n",
672
+ "\n",
673
+ " [[ 13, 14, 15],\n",
674
+ " [ 16, 17, 18],\n",
675
+ " [ 19, 20, 21],\n",
676
+ " [ 22, 23, 24],\n",
677
+ " [113, 114, 115],\n",
678
+ " [116, 117, 118],\n",
679
+ " [119, 120, 121],\n",
680
+ " [122, 123, 124]],\n",
681
+ "\n",
682
+ " [[ 25, 26, 27],\n",
683
+ " [ 28, 29, 30],\n",
684
+ " [ 31, 32, 33],\n",
685
+ " [ 34, 35, 36],\n",
686
+ " [125, 126, 127],\n",
687
+ " [128, 129, 130],\n",
688
+ " [131, 132, 133],\n",
689
+ " [134, 135, 136]]])"
690
+ ]
691
+ },
692
+ "execution_count": 61,
693
+ "metadata": {},
694
+ "output_type": "execute_result"
695
+ }
696
+ ],
697
+ "source": [
698
+ "np.concatenate([aa, bb], axis=1)"
699
+ ]
700
+ },
701
+ {
702
+ "cell_type": "code",
703
+ "execution_count": 62,
704
+ "metadata": {},
705
+ "outputs": [
706
+ {
707
+ "data": {
708
+ "text/plain": [
709
+ "array([[[ 1, 2, 3, 101, 102, 103],\n",
710
+ " [ 4, 5, 6, 104, 105, 106],\n",
711
+ " [ 7, 8, 9, 107, 108, 109],\n",
712
+ " [ 10, 11, 12, 110, 111, 112]],\n",
713
+ "\n",
714
+ " [[ 13, 14, 15, 113, 114, 115],\n",
715
+ " [ 16, 17, 18, 116, 117, 118],\n",
716
+ " [ 19, 20, 21, 119, 120, 121],\n",
717
+ " [ 22, 23, 24, 122, 123, 124]],\n",
718
+ "\n",
719
+ " [[ 25, 26, 27, 125, 126, 127],\n",
720
+ " [ 28, 29, 30, 128, 129, 130],\n",
721
+ " [ 31, 32, 33, 131, 132, 133],\n",
722
+ " [ 34, 35, 36, 134, 135, 136]]])"
723
+ ]
724
+ },
725
+ "execution_count": 62,
726
+ "metadata": {},
727
+ "output_type": "execute_result"
728
+ }
729
+ ],
730
+ "source": [
731
+ "np.concatenate([aa, bb], axis=2)"
732
+ ]
733
+ },
734
+ {
735
+ "cell_type": "code",
736
+ "execution_count": null,
737
+ "metadata": {
738
+ "collapsed": true
739
+ },
740
+ "outputs": [],
741
+ "source": []
742
+ }
743
+ ],
744
+ "metadata": {
745
+ "kernelspec": {
746
+ "display_name": "Python 3",
747
+ "language": "python",
748
+ "name": "python3"
749
+ },
750
+ "language_info": {
751
+ "codemirror_mode": {
752
+ "name": "ipython",
753
+ "version": 3
754
+ },
755
+ "file_extension": ".py",
756
+ "mimetype": "text/x-python",
757
+ "name": "python",
758
+ "nbconvert_exporter": "python",
759
+ "pygments_lexer": "ipython3",
760
+ "version": "3.6.3"
761
+ }
762
+ },
763
+ "nbformat": 4,
764
+ "nbformat_minor": 2
765
+ }
Python_split.ipynb ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {
7
+ "collapsed": true
8
+ },
9
+ "outputs": [],
10
+ "source": [
11
+ "import numpy as np"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": 3,
17
+ "metadata": {},
18
+ "outputs": [
19
+ {
20
+ "data": {
21
+ "text/plain": [
22
+ "array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11])"
23
+ ]
24
+ },
25
+ "execution_count": 3,
26
+ "metadata": {},
27
+ "output_type": "execute_result"
28
+ }
29
+ ],
30
+ "source": [
31
+ "arr = np.arange(12)\n",
32
+ "arr"
33
+ ]
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "execution_count": 5,
38
+ "metadata": {},
39
+ "outputs": [
40
+ {
41
+ "data": {
42
+ "text/plain": [
43
+ "[array([0, 1, 2]), array([3, 4, 5]), array([6, 7, 8]), array([ 9, 10, 11])]"
44
+ ]
45
+ },
46
+ "execution_count": 5,
47
+ "metadata": {},
48
+ "output_type": "execute_result"
49
+ }
50
+ ],
51
+ "source": [
52
+ "np.split(arr, 4)"
53
+ ]
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "execution_count": 6,
58
+ "metadata": {},
59
+ "outputs": [
60
+ {
61
+ "data": {
62
+ "text/plain": [
63
+ "[array([0, 1, 2]), array([3, 4]), array([ 5, 6, 7, 8, 9, 10, 11])]"
64
+ ]
65
+ },
66
+ "execution_count": 6,
67
+ "metadata": {},
68
+ "output_type": "execute_result"
69
+ }
70
+ ],
71
+ "source": [
72
+ "np.split(arr, [3,5])"
73
+ ]
74
+ },
75
+ {
76
+ "cell_type": "code",
77
+ "execution_count": 7,
78
+ "metadata": {},
79
+ "outputs": [
80
+ {
81
+ "data": {
82
+ "text/plain": [
83
+ "array([[ 1, 2, 3],\n",
84
+ " [ 4, 5, 6],\n",
85
+ " [11, 12, 13],\n",
86
+ " [14, 15, 16]])"
87
+ ]
88
+ },
89
+ "execution_count": 7,
90
+ "metadata": {},
91
+ "output_type": "execute_result"
92
+ }
93
+ ],
94
+ "source": [
95
+ "a=np.array([[1,2,3],[4,5,6],[11,12,13],[14,15,16]])\n",
96
+ "a"
97
+ ]
98
+ },
99
+ {
100
+ "cell_type": "code",
101
+ "execution_count": 8,
102
+ "metadata": {},
103
+ "outputs": [
104
+ {
105
+ "data": {
106
+ "text/plain": [
107
+ "[array([[1, 2, 3],\n",
108
+ " [4, 5, 6]]), array([[11, 12, 13],\n",
109
+ " [14, 15, 16]])]"
110
+ ]
111
+ },
112
+ "execution_count": 8,
113
+ "metadata": {},
114
+ "output_type": "execute_result"
115
+ }
116
+ ],
117
+ "source": [
118
+ "np.split(a,2,axis=0)"
119
+ ]
120
+ },
121
+ {
122
+ "cell_type": "code",
123
+ "execution_count": 10,
124
+ "metadata": {},
125
+ "outputs": [
126
+ {
127
+ "data": {
128
+ "text/plain": [
129
+ "[array([[ 1, 2],\n",
130
+ " [ 5, 6],\n",
131
+ " [13, 14]]), array([[ 3, 4],\n",
132
+ " [11, 12],\n",
133
+ " [15, 16]])]"
134
+ ]
135
+ },
136
+ "execution_count": 10,
137
+ "metadata": {},
138
+ "output_type": "execute_result"
139
+ }
140
+ ],
141
+ "source": [
142
+ "a = a.reshape(3,4)\n",
143
+ "np.split(a,2,axis=1)"
144
+ ]
145
+ },
146
+ {
147
+ "cell_type": "code",
148
+ "execution_count": 11,
149
+ "metadata": {},
150
+ "outputs": [
151
+ {
152
+ "data": {
153
+ "text/plain": [
154
+ "array([[ 1, 2, 3, 4],\n",
155
+ " [ 5, 6, 11, 12],\n",
156
+ " [13, 14, 15, 16]])"
157
+ ]
158
+ },
159
+ "execution_count": 11,
160
+ "metadata": {},
161
+ "output_type": "execute_result"
162
+ }
163
+ ],
164
+ "source": [
165
+ "a"
166
+ ]
167
+ },
168
+ {
169
+ "cell_type": "code",
170
+ "execution_count": 12,
171
+ "metadata": {},
172
+ "outputs": [
173
+ {
174
+ "data": {
175
+ "text/plain": [
176
+ "array([[ 1, 5, 13],\n",
177
+ " [ 2, 6, 14],\n",
178
+ " [ 3, 11, 15],\n",
179
+ " [ 4, 12, 16]])"
180
+ ]
181
+ },
182
+ "execution_count": 12,
183
+ "metadata": {},
184
+ "output_type": "execute_result"
185
+ }
186
+ ],
187
+ "source": [
188
+ "np.transpose(a)"
189
+ ]
190
+ },
191
+ {
192
+ "cell_type": "code",
193
+ "execution_count": 13,
194
+ "metadata": {},
195
+ "outputs": [
196
+ {
197
+ "data": {
198
+ "text/plain": [
199
+ "array([[ 1, 5, 13],\n",
200
+ " [ 2, 6, 14],\n",
201
+ " [ 3, 11, 15],\n",
202
+ " [ 4, 12, 16]])"
203
+ ]
204
+ },
205
+ "execution_count": 13,
206
+ "metadata": {},
207
+ "output_type": "execute_result"
208
+ }
209
+ ],
210
+ "source": [
211
+ "a.transpose()"
212
+ ]
213
+ },
214
+ {
215
+ "cell_type": "code",
216
+ "execution_count": null,
217
+ "metadata": {
218
+ "collapsed": true
219
+ },
220
+ "outputs": [],
221
+ "source": []
222
+ }
223
+ ],
224
+ "metadata": {
225
+ "kernelspec": {
226
+ "display_name": "Python 3",
227
+ "language": "python",
228
+ "name": "python3"
229
+ },
230
+ "language_info": {
231
+ "codemirror_mode": {
232
+ "name": "ipython",
233
+ "version": 3
234
+ },
235
+ "file_extension": ".py",
236
+ "mimetype": "text/x-python",
237
+ "name": "python",
238
+ "nbconvert_exporter": "python",
239
+ "pygments_lexer": "ipython3",
240
+ "version": "3.6.3"
241
+ }
242
+ },
243
+ "nbformat": 4,
244
+ "nbformat_minor": 2
245
+ }
Python_算术运算_向上向下取整_聚合函数.ipynb ADDED
@@ -0,0 +1,811 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {
7
+ "collapsed": true
8
+ },
9
+ "outputs": [],
10
+ "source": [
11
+ "import numpy as np"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": 3,
17
+ "metadata": {},
18
+ "outputs": [
19
+ {
20
+ "data": {
21
+ "text/plain": [
22
+ "array([[0, 1, 2],\n",
23
+ " [3, 4, 5],\n",
24
+ " [6, 7, 8]])"
25
+ ]
26
+ },
27
+ "execution_count": 3,
28
+ "metadata": {},
29
+ "output_type": "execute_result"
30
+ }
31
+ ],
32
+ "source": [
33
+ "a = np.arange(9).reshape(3,3)\n",
34
+ "a"
35
+ ]
36
+ },
37
+ {
38
+ "cell_type": "code",
39
+ "execution_count": 4,
40
+ "metadata": {},
41
+ "outputs": [
42
+ {
43
+ "data": {
44
+ "text/plain": [
45
+ "array([[0, 1, 2],\n",
46
+ " [3, 4, 5],\n",
47
+ " [6, 7, 8]])"
48
+ ]
49
+ },
50
+ "execution_count": 4,
51
+ "metadata": {},
52
+ "output_type": "execute_result"
53
+ }
54
+ ],
55
+ "source": [
56
+ "b = np.arange(9).reshape(3,3)\n",
57
+ "b"
58
+ ]
59
+ },
60
+ {
61
+ "cell_type": "code",
62
+ "execution_count": 8,
63
+ "metadata": {},
64
+ "outputs": [
65
+ {
66
+ "data": {
67
+ "text/plain": [
68
+ "array([[ 0, 2, 4],\n",
69
+ " [ 6, 8, 10],\n",
70
+ " [12, 14, 16]])"
71
+ ]
72
+ },
73
+ "execution_count": 8,
74
+ "metadata": {},
75
+ "output_type": "execute_result"
76
+ }
77
+ ],
78
+ "source": [
79
+ "a + b"
80
+ ]
81
+ },
82
+ {
83
+ "cell_type": "code",
84
+ "execution_count": 6,
85
+ "metadata": {},
86
+ "outputs": [
87
+ {
88
+ "data": {
89
+ "text/plain": [
90
+ "array([[ 0, 2, 4],\n",
91
+ " [ 6, 8, 10],\n",
92
+ " [12, 14, 16]])"
93
+ ]
94
+ },
95
+ "execution_count": 6,
96
+ "metadata": {},
97
+ "output_type": "execute_result"
98
+ }
99
+ ],
100
+ "source": [
101
+ "np.add(a, b)"
102
+ ]
103
+ },
104
+ {
105
+ "cell_type": "code",
106
+ "execution_count": 9,
107
+ "metadata": {},
108
+ "outputs": [
109
+ {
110
+ "data": {
111
+ "text/plain": [
112
+ "array([[0, 0, 0],\n",
113
+ " [0, 0, 0],\n",
114
+ " [0, 0, 0]])"
115
+ ]
116
+ },
117
+ "execution_count": 9,
118
+ "metadata": {},
119
+ "output_type": "execute_result"
120
+ }
121
+ ],
122
+ "source": [
123
+ "a-b"
124
+ ]
125
+ },
126
+ {
127
+ "cell_type": "code",
128
+ "execution_count": 11,
129
+ "metadata": {},
130
+ "outputs": [
131
+ {
132
+ "data": {
133
+ "text/plain": [
134
+ "array([[0, 0, 0],\n",
135
+ " [0, 0, 0],\n",
136
+ " [0, 0, 0]])"
137
+ ]
138
+ },
139
+ "execution_count": 11,
140
+ "metadata": {},
141
+ "output_type": "execute_result"
142
+ }
143
+ ],
144
+ "source": [
145
+ "np.subtract(a,b)"
146
+ ]
147
+ },
148
+ {
149
+ "cell_type": "code",
150
+ "execution_count": 12,
151
+ "metadata": {},
152
+ "outputs": [
153
+ {
154
+ "data": {
155
+ "text/plain": [
156
+ "array([2, 3, 4])"
157
+ ]
158
+ },
159
+ "execution_count": 12,
160
+ "metadata": {},
161
+ "output_type": "execute_result"
162
+ }
163
+ ],
164
+ "source": [
165
+ "c = np.array([2,3,4])\n",
166
+ "c"
167
+ ]
168
+ },
169
+ {
170
+ "cell_type": "code",
171
+ "execution_count": 14,
172
+ "metadata": {},
173
+ "outputs": [
174
+ {
175
+ "data": {
176
+ "text/plain": [
177
+ "array([[0, 1, 2],\n",
178
+ " [3, 4, 5],\n",
179
+ " [6, 7, 8]])"
180
+ ]
181
+ },
182
+ "execution_count": 14,
183
+ "metadata": {},
184
+ "output_type": "execute_result"
185
+ }
186
+ ],
187
+ "source": [
188
+ "a"
189
+ ]
190
+ },
191
+ {
192
+ "cell_type": "code",
193
+ "execution_count": 13,
194
+ "metadata": {},
195
+ "outputs": [
196
+ {
197
+ "data": {
198
+ "text/plain": [
199
+ "array([[ 2, 4, 6],\n",
200
+ " [ 5, 7, 9],\n",
201
+ " [ 8, 10, 12]])"
202
+ ]
203
+ },
204
+ "execution_count": 13,
205
+ "metadata": {},
206
+ "output_type": "execute_result"
207
+ }
208
+ ],
209
+ "source": [
210
+ "a + c"
211
+ ]
212
+ },
213
+ {
214
+ "cell_type": "code",
215
+ "execution_count": 15,
216
+ "metadata": {},
217
+ "outputs": [
218
+ {
219
+ "data": {
220
+ "text/plain": [
221
+ "array([[-2, -2, -2],\n",
222
+ " [ 1, 1, 1],\n",
223
+ " [ 4, 4, 4]])"
224
+ ]
225
+ },
226
+ "execution_count": 15,
227
+ "metadata": {},
228
+ "output_type": "execute_result"
229
+ }
230
+ ],
231
+ "source": [
232
+ "a-c"
233
+ ]
234
+ },
235
+ {
236
+ "cell_type": "code",
237
+ "execution_count": 16,
238
+ "metadata": {},
239
+ "outputs": [
240
+ {
241
+ "data": {
242
+ "text/plain": [
243
+ "array([0, 1, 2, 3, 4])"
244
+ ]
245
+ },
246
+ "execution_count": 16,
247
+ "metadata": {},
248
+ "output_type": "execute_result"
249
+ }
250
+ ],
251
+ "source": [
252
+ "x = np.arange(5)\n",
253
+ "x"
254
+ ]
255
+ },
256
+ {
257
+ "cell_type": "code",
258
+ "execution_count": 17,
259
+ "metadata": {},
260
+ "outputs": [
261
+ {
262
+ "data": {
263
+ "text/plain": [
264
+ "array([ 0, 10, 20, 30, 40])"
265
+ ]
266
+ },
267
+ "execution_count": 17,
268
+ "metadata": {},
269
+ "output_type": "execute_result"
270
+ }
271
+ ],
272
+ "source": [
273
+ "x * 10"
274
+ ]
275
+ },
276
+ {
277
+ "cell_type": "code",
278
+ "execution_count": 18,
279
+ "metadata": {},
280
+ "outputs": [
281
+ {
282
+ "data": {
283
+ "text/plain": [
284
+ "array([ 0, 10, 20, 30, 40])"
285
+ ]
286
+ },
287
+ "execution_count": 18,
288
+ "metadata": {},
289
+ "output_type": "execute_result"
290
+ }
291
+ ],
292
+ "source": [
293
+ "y = np.multiply(x, 10)\n",
294
+ "y"
295
+ ]
296
+ },
297
+ {
298
+ "cell_type": "code",
299
+ "execution_count": 20,
300
+ "metadata": {},
301
+ "outputs": [
302
+ {
303
+ "data": {
304
+ "text/plain": [
305
+ "array([1.49530576e-311, 6.79038653e-313, 1.01855798e-312, 0.00000000e+000,\n",
306
+ " 1.07605111e-282])"
307
+ ]
308
+ },
309
+ "execution_count": 20,
310
+ "metadata": {},
311
+ "output_type": "execute_result"
312
+ }
313
+ ],
314
+ "source": [
315
+ "y = np.empty(5)\n",
316
+ "y"
317
+ ]
318
+ },
319
+ {
320
+ "cell_type": "code",
321
+ "execution_count": 21,
322
+ "metadata": {},
323
+ "outputs": [
324
+ {
325
+ "data": {
326
+ "text/plain": [
327
+ "array([ 0., 10., 20., 30., 40.])"
328
+ ]
329
+ },
330
+ "execution_count": 21,
331
+ "metadata": {},
332
+ "output_type": "execute_result"
333
+ }
334
+ ],
335
+ "source": [
336
+ "np.multiply(x, 10, out=y)"
337
+ ]
338
+ },
339
+ {
340
+ "cell_type": "code",
341
+ "execution_count": 22,
342
+ "metadata": {},
343
+ "outputs": [
344
+ {
345
+ "data": {
346
+ "text/plain": [
347
+ "array([ 0., 10., 20., 30., 40.])"
348
+ ]
349
+ },
350
+ "execution_count": 22,
351
+ "metadata": {},
352
+ "output_type": "execute_result"
353
+ }
354
+ ],
355
+ "source": [
356
+ "y"
357
+ ]
358
+ },
359
+ {
360
+ "cell_type": "code",
361
+ "execution_count": 23,
362
+ "metadata": {},
363
+ "outputs": [
364
+ {
365
+ "data": {
366
+ "text/plain": [
367
+ "4.0"
368
+ ]
369
+ },
370
+ "execution_count": 23,
371
+ "metadata": {},
372
+ "output_type": "execute_result"
373
+ }
374
+ ],
375
+ "source": [
376
+ "np.around(4.5)"
377
+ ]
378
+ },
379
+ {
380
+ "cell_type": "code",
381
+ "execution_count": 24,
382
+ "metadata": {},
383
+ "outputs": [
384
+ {
385
+ "data": {
386
+ "text/plain": [
387
+ "5.0"
388
+ ]
389
+ },
390
+ "execution_count": 24,
391
+ "metadata": {},
392
+ "output_type": "execute_result"
393
+ }
394
+ ],
395
+ "source": [
396
+ "np.around(4.6)"
397
+ ]
398
+ },
399
+ {
400
+ "cell_type": "code",
401
+ "execution_count": 25,
402
+ "metadata": {},
403
+ "outputs": [
404
+ {
405
+ "data": {
406
+ "text/plain": [
407
+ "4.0"
408
+ ]
409
+ },
410
+ "execution_count": 25,
411
+ "metadata": {},
412
+ "output_type": "execute_result"
413
+ }
414
+ ],
415
+ "source": [
416
+ "np.floor(4.5)"
417
+ ]
418
+ },
419
+ {
420
+ "cell_type": "code",
421
+ "execution_count": 26,
422
+ "metadata": {},
423
+ "outputs": [
424
+ {
425
+ "data": {
426
+ "text/plain": [
427
+ "4.0"
428
+ ]
429
+ },
430
+ "execution_count": 26,
431
+ "metadata": {},
432
+ "output_type": "execute_result"
433
+ }
434
+ ],
435
+ "source": [
436
+ "np.floor(4.1)"
437
+ ]
438
+ },
439
+ {
440
+ "cell_type": "code",
441
+ "execution_count": 27,
442
+ "metadata": {},
443
+ "outputs": [
444
+ {
445
+ "data": {
446
+ "text/plain": [
447
+ "5.0"
448
+ ]
449
+ },
450
+ "execution_count": 27,
451
+ "metadata": {},
452
+ "output_type": "execute_result"
453
+ }
454
+ ],
455
+ "source": [
456
+ "np.ceil(4.1)"
457
+ ]
458
+ },
459
+ {
460
+ "cell_type": "code",
461
+ "execution_count": 28,
462
+ "metadata": {},
463
+ "outputs": [
464
+ {
465
+ "data": {
466
+ "text/plain": [
467
+ "array([1, 2, 3, 5, 5])"
468
+ ]
469
+ },
470
+ "execution_count": 28,
471
+ "metadata": {},
472
+ "output_type": "execute_result"
473
+ }
474
+ ],
475
+ "source": [
476
+ "temp = np.array([1,2,3,5,5])\n",
477
+ "temp"
478
+ ]
479
+ },
480
+ {
481
+ "cell_type": "code",
482
+ "execution_count": 29,
483
+ "metadata": {},
484
+ "outputs": [
485
+ {
486
+ "data": {
487
+ "text/plain": [
488
+ "16"
489
+ ]
490
+ },
491
+ "execution_count": 29,
492
+ "metadata": {},
493
+ "output_type": "execute_result"
494
+ }
495
+ ],
496
+ "source": [
497
+ "np.sum(temp)"
498
+ ]
499
+ },
500
+ {
501
+ "cell_type": "code",
502
+ "execution_count": 30,
503
+ "metadata": {},
504
+ "outputs": [
505
+ {
506
+ "data": {
507
+ "text/plain": [
508
+ "150"
509
+ ]
510
+ },
511
+ "execution_count": 30,
512
+ "metadata": {},
513
+ "output_type": "execute_result"
514
+ }
515
+ ],
516
+ "source": [
517
+ "np.prod(temp)"
518
+ ]
519
+ },
520
+ {
521
+ "cell_type": "code",
522
+ "execution_count": 31,
523
+ "metadata": {},
524
+ "outputs": [
525
+ {
526
+ "data": {
527
+ "text/plain": [
528
+ "3.2"
529
+ ]
530
+ },
531
+ "execution_count": 31,
532
+ "metadata": {},
533
+ "output_type": "execute_result"
534
+ }
535
+ ],
536
+ "source": [
537
+ "np.mean(temp)"
538
+ ]
539
+ },
540
+ {
541
+ "cell_type": "code",
542
+ "execution_count": 32,
543
+ "metadata": {},
544
+ "outputs": [
545
+ {
546
+ "data": {
547
+ "text/plain": [
548
+ "2.56"
549
+ ]
550
+ },
551
+ "execution_count": 32,
552
+ "metadata": {},
553
+ "output_type": "execute_result"
554
+ }
555
+ ],
556
+ "source": [
557
+ "np.var(temp)"
558
+ ]
559
+ },
560
+ {
561
+ "cell_type": "code",
562
+ "execution_count": 33,
563
+ "metadata": {},
564
+ "outputs": [
565
+ {
566
+ "data": {
567
+ "text/plain": [
568
+ "1.6"
569
+ ]
570
+ },
571
+ "execution_count": 33,
572
+ "metadata": {},
573
+ "output_type": "execute_result"
574
+ }
575
+ ],
576
+ "source": [
577
+ "np.std(temp)"
578
+ ]
579
+ },
580
+ {
581
+ "cell_type": "code",
582
+ "execution_count": 34,
583
+ "metadata": {},
584
+ "outputs": [
585
+ {
586
+ "data": {
587
+ "text/plain": [
588
+ "3.0"
589
+ ]
590
+ },
591
+ "execution_count": 34,
592
+ "metadata": {},
593
+ "output_type": "execute_result"
594
+ }
595
+ ],
596
+ "source": [
597
+ "np.median(temp)"
598
+ ]
599
+ },
600
+ {
601
+ "cell_type": "code",
602
+ "execution_count": 36,
603
+ "metadata": {},
604
+ "outputs": [
605
+ {
606
+ "data": {
607
+ "text/plain": [
608
+ "array([ 1, 4, 9, 25, 25], dtype=int32)"
609
+ ]
610
+ },
611
+ "execution_count": 36,
612
+ "metadata": {},
613
+ "output_type": "execute_result"
614
+ }
615
+ ],
616
+ "source": [
617
+ "np.power(temp,2)"
618
+ ]
619
+ },
620
+ {
621
+ "cell_type": "code",
622
+ "execution_count": 37,
623
+ "metadata": {},
624
+ "outputs": [
625
+ {
626
+ "data": {
627
+ "text/plain": [
628
+ "array([1. , 1.41421356, 1.73205081, 2.23606798, 2.23606798])"
629
+ ]
630
+ },
631
+ "execution_count": 37,
632
+ "metadata": {},
633
+ "output_type": "execute_result"
634
+ }
635
+ ],
636
+ "source": [
637
+ "np.sqrt(temp)"
638
+ ]
639
+ },
640
+ {
641
+ "cell_type": "code",
642
+ "execution_count": 38,
643
+ "metadata": {},
644
+ "outputs": [
645
+ {
646
+ "data": {
647
+ "text/plain": [
648
+ "1"
649
+ ]
650
+ },
651
+ "execution_count": 38,
652
+ "metadata": {},
653
+ "output_type": "execute_result"
654
+ }
655
+ ],
656
+ "source": [
657
+ "np.min(temp)"
658
+ ]
659
+ },
660
+ {
661
+ "cell_type": "code",
662
+ "execution_count": 39,
663
+ "metadata": {},
664
+ "outputs": [
665
+ {
666
+ "data": {
667
+ "text/plain": [
668
+ "5"
669
+ ]
670
+ },
671
+ "execution_count": 39,
672
+ "metadata": {},
673
+ "output_type": "execute_result"
674
+ }
675
+ ],
676
+ "source": [
677
+ "np.max(temp)"
678
+ ]
679
+ },
680
+ {
681
+ "cell_type": "code",
682
+ "execution_count": 40,
683
+ "metadata": {},
684
+ "outputs": [
685
+ {
686
+ "data": {
687
+ "text/plain": [
688
+ "0"
689
+ ]
690
+ },
691
+ "execution_count": 40,
692
+ "metadata": {},
693
+ "output_type": "execute_result"
694
+ }
695
+ ],
696
+ "source": [
697
+ "np.argmin(temp)"
698
+ ]
699
+ },
700
+ {
701
+ "cell_type": "code",
702
+ "execution_count": 41,
703
+ "metadata": {},
704
+ "outputs": [
705
+ {
706
+ "data": {
707
+ "text/plain": [
708
+ "3"
709
+ ]
710
+ },
711
+ "execution_count": 41,
712
+ "metadata": {},
713
+ "output_type": "execute_result"
714
+ }
715
+ ],
716
+ "source": [
717
+ "np.argmax(temp)"
718
+ ]
719
+ },
720
+ {
721
+ "cell_type": "code",
722
+ "execution_count": 42,
723
+ "metadata": {},
724
+ "outputs": [
725
+ {
726
+ "data": {
727
+ "text/plain": [
728
+ "22026.465794806718"
729
+ ]
730
+ },
731
+ "execution_count": 42,
732
+ "metadata": {},
733
+ "output_type": "execute_result"
734
+ }
735
+ ],
736
+ "source": [
737
+ "np.exp(10)"
738
+ ]
739
+ },
740
+ {
741
+ "cell_type": "code",
742
+ "execution_count": 43,
743
+ "metadata": {},
744
+ "outputs": [
745
+ {
746
+ "data": {
747
+ "text/plain": [
748
+ "2.302585092994046"
749
+ ]
750
+ },
751
+ "execution_count": 43,
752
+ "metadata": {},
753
+ "output_type": "execute_result"
754
+ }
755
+ ],
756
+ "source": [
757
+ "np.log(10)"
758
+ ]
759
+ },
760
+ {
761
+ "cell_type": "code",
762
+ "execution_count": 44,
763
+ "metadata": {},
764
+ "outputs": [
765
+ {
766
+ "data": {
767
+ "text/plain": [
768
+ "10.0"
769
+ ]
770
+ },
771
+ "execution_count": 44,
772
+ "metadata": {},
773
+ "output_type": "execute_result"
774
+ }
775
+ ],
776
+ "source": [
777
+ "np.log(np.exp(10))"
778
+ ]
779
+ },
780
+ {
781
+ "cell_type": "code",
782
+ "execution_count": null,
783
+ "metadata": {
784
+ "collapsed": true
785
+ },
786
+ "outputs": [],
787
+ "source": []
788
+ }
789
+ ],
790
+ "metadata": {
791
+ "kernelspec": {
792
+ "display_name": "Python 3",
793
+ "language": "python",
794
+ "name": "python3"
795
+ },
796
+ "language_info": {
797
+ "codemirror_mode": {
798
+ "name": "ipython",
799
+ "version": 3
800
+ },
801
+ "file_extension": ".py",
802
+ "mimetype": "text/x-python",
803
+ "name": "python",
804
+ "nbconvert_exporter": "python",
805
+ "pygments_lexer": "ipython3",
806
+ "version": "3.6.3"
807
+ }
808
+ },
809
+ "nbformat": 4,
810
+ "nbformat_minor": 2
811
+ }
debug.log ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ [1008/132332.628:ERROR:filesystem_win.cc(129)] GetFileAttributes C:\Users\root\AppData\Local\Google\Chrome\User Data\Crashpad\attachments\2381b32c-86ea-4c18-b9e3-7cd31a7004e4: ϵͳ�Ҳ���ָ����·���� (0x3)
2
+ [1008/132332.632:ERROR:directory_reader_win.cc(43)] FindFirstFile: ϵͳ�Ҳ���ָ����·���� (0x3)
3
+ [1009/132351.489:ERROR:directory_reader_win.cc(43)] FindFirstFile: ϵͳ�Ҳ���ָ����·���� (0x3)
4
+ [1010/132351.504:ERROR:directory_reader_win.cc(43)] FindFirstFile: ϵͳ�Ҳ���ָ����·���� (0x3)
5
+ [1012/105819.065:ERROR:directory_reader_win.cc(43)] FindFirstFile: ϵͳ�Ҳ���ָ����·���� (0x3)
python_dict_set.ipynb ADDED
@@ -0,0 +1,245 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 5,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "data": {
10
+ "text/plain": [
11
+ "{'他': 3, '你': 2, '天安门': 5, '我': 1, '爱': 4}"
12
+ ]
13
+ },
14
+ "execution_count": 5,
15
+ "metadata": {},
16
+ "output_type": "execute_result"
17
+ }
18
+ ],
19
+ "source": [
20
+ "a = [1, 2, 3, 4, 5]\n",
21
+ "b = ['我', '你', '他', '爱', '天安门']\n",
22
+ "dict(zip(b,a))"
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": 6,
28
+ "metadata": {},
29
+ "outputs": [
30
+ {
31
+ "data": {
32
+ "text/plain": [
33
+ "2"
34
+ ]
35
+ },
36
+ "execution_count": 6,
37
+ "metadata": {},
38
+ "output_type": "execute_result"
39
+ }
40
+ ],
41
+ "source": [
42
+ "c = dict(zip(b,a))\n",
43
+ "c['你']"
44
+ ]
45
+ },
46
+ {
47
+ "cell_type": "code",
48
+ "execution_count": 10,
49
+ "metadata": {},
50
+ "outputs": [
51
+ {
52
+ "data": {
53
+ "text/plain": [
54
+ "[1, 4, 5]"
55
+ ]
56
+ },
57
+ "execution_count": 10,
58
+ "metadata": {},
59
+ "output_type": "execute_result"
60
+ }
61
+ ],
62
+ "source": [
63
+ "sentence = '我 爱 天安门'\n",
64
+ "words = sentence.split(' ')\n",
65
+ "[c[word] for word in words]"
66
+ ]
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "execution_count": 14,
71
+ "metadata": {},
72
+ "outputs": [
73
+ {
74
+ "data": {
75
+ "text/plain": [
76
+ "{'他': 3, '你': 2, '天安门': 5, '尚学堂': 6, '我': 1, '爱': 4}"
77
+ ]
78
+ },
79
+ "execution_count": 14,
80
+ "metadata": {},
81
+ "output_type": "execute_result"
82
+ }
83
+ ],
84
+ "source": [
85
+ "c['尚学堂'] = 6\n",
86
+ "c"
87
+ ]
88
+ },
89
+ {
90
+ "cell_type": "code",
91
+ "execution_count": 16,
92
+ "metadata": {},
93
+ "outputs": [
94
+ {
95
+ "name": "stdout",
96
+ "output_type": "stream",
97
+ "text": [
98
+ "('我', 1)\n",
99
+ "('你', 2)\n",
100
+ "('他', 3)\n",
101
+ "('爱', 4)\n",
102
+ "('天安门', 5)\n",
103
+ "('尚学堂', 6)\n"
104
+ ]
105
+ }
106
+ ],
107
+ "source": [
108
+ "for item in c.items():\n",
109
+ " print(item)"
110
+ ]
111
+ },
112
+ {
113
+ "cell_type": "code",
114
+ "execution_count": 18,
115
+ "metadata": {},
116
+ "outputs": [
117
+ {
118
+ "name": "stdout",
119
+ "output_type": "stream",
120
+ "text": [
121
+ "我 1\n",
122
+ "你 2\n",
123
+ "他 3\n",
124
+ "爱 4\n",
125
+ "天安门 5\n",
126
+ "尚学堂 6\n"
127
+ ]
128
+ }
129
+ ],
130
+ "source": [
131
+ "for key in c.keys():\n",
132
+ " print(key, c[key])"
133
+ ]
134
+ },
135
+ {
136
+ "cell_type": "code",
137
+ "execution_count": 19,
138
+ "metadata": {},
139
+ "outputs": [
140
+ {
141
+ "name": "stdout",
142
+ "output_type": "stream",
143
+ "text": [
144
+ "1\n",
145
+ "2\n",
146
+ "3\n",
147
+ "4\n",
148
+ "5\n",
149
+ "6\n"
150
+ ]
151
+ }
152
+ ],
153
+ "source": [
154
+ "for value in c.values():\n",
155
+ " print(value)"
156
+ ]
157
+ },
158
+ {
159
+ "cell_type": "code",
160
+ "execution_count": 20,
161
+ "metadata": {},
162
+ "outputs": [
163
+ {
164
+ "name": "stdout",
165
+ "output_type": "stream",
166
+ "text": [
167
+ "0 我 1\n",
168
+ "1 你 2\n",
169
+ "2 他 3\n",
170
+ "3 爱 4\n",
171
+ "4 天安门 5\n",
172
+ "5 尚学堂 6\n"
173
+ ]
174
+ }
175
+ ],
176
+ "source": [
177
+ "for i, key in enumerate(c):\n",
178
+ " print(i, key, c[key])"
179
+ ]
180
+ },
181
+ {
182
+ "cell_type": "code",
183
+ "execution_count": 22,
184
+ "metadata": {},
185
+ "outputs": [
186
+ {
187
+ "name": "stdout",
188
+ "output_type": "stream",
189
+ "text": [
190
+ "0 10\n",
191
+ "1 20\n",
192
+ "2 30\n"
193
+ ]
194
+ }
195
+ ],
196
+ "source": [
197
+ "aList = [10, 20 , 30]\n",
198
+ "for i, value in enumerate(aList):\n",
199
+ " print(i, value)"
200
+ ]
201
+ },
202
+ {
203
+ "cell_type": "code",
204
+ "execution_count": 23,
205
+ "metadata": {},
206
+ "outputs": [
207
+ {
208
+ "data": {
209
+ "text/plain": [
210
+ "{1, 2, 3, 5}"
211
+ ]
212
+ },
213
+ "execution_count": 23,
214
+ "metadata": {},
215
+ "output_type": "execute_result"
216
+ }
217
+ ],
218
+ "source": [
219
+ "a = {1, 2, 3, 5, 5}\n",
220
+ "a"
221
+ ]
222
+ }
223
+ ],
224
+ "metadata": {
225
+ "kernelspec": {
226
+ "display_name": "Python 3",
227
+ "language": "python",
228
+ "name": "python3"
229
+ },
230
+ "language_info": {
231
+ "codemirror_mode": {
232
+ "name": "ipython",
233
+ "version": 3
234
+ },
235
+ "file_extension": ".py",
236
+ "mimetype": "text/x-python",
237
+ "name": "python",
238
+ "nbconvert_exporter": "python",
239
+ "pygments_lexer": "ipython3",
240
+ "version": "3.6.3"
241
+ }
242
+ },
243
+ "nbformat": 4,
244
+ "nbformat_minor": 2
245
+ }
python_function.ipynb ADDED
@@ -0,0 +1,593 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {
7
+ "collapsed": true
8
+ },
9
+ "outputs": [],
10
+ "source": [
11
+ "def mytest():\n",
12
+ " print('mytest function')"
13
+ ]
14
+ },
15
+ {
16
+ "cell_type": "code",
17
+ "execution_count": 3,
18
+ "metadata": {},
19
+ "outputs": [
20
+ {
21
+ "name": "stdout",
22
+ "output_type": "stream",
23
+ "text": [
24
+ "mytest function\n"
25
+ ]
26
+ }
27
+ ],
28
+ "source": [
29
+ "mytest()"
30
+ ]
31
+ },
32
+ {
33
+ "cell_type": "code",
34
+ "execution_count": 5,
35
+ "metadata": {},
36
+ "outputs": [
37
+ {
38
+ "name": "stdout",
39
+ "output_type": "stream",
40
+ "text": [
41
+ "my name is yasaka, my age is 19\n"
42
+ ]
43
+ }
44
+ ],
45
+ "source": [
46
+ "def mytest(name, age):\n",
47
+ " print('my name is %s, my age is %d' % (name, age))\n",
48
+ " \n",
49
+ "mytest('yasaka', 19)"
50
+ ]
51
+ },
52
+ {
53
+ "cell_type": "code",
54
+ "execution_count": 29,
55
+ "metadata": {},
56
+ "outputs": [
57
+ {
58
+ "name": "stdout",
59
+ "output_type": "stream",
60
+ "text": [
61
+ "my name is yasaka, my age is 18\n",
62
+ "my name is yasaka, my age is 28\n",
63
+ "my name is yasaka, my age is 28\n",
64
+ "my name is yasaka, my age is 28\n"
65
+ ]
66
+ }
67
+ ],
68
+ "source": [
69
+ "def mytest(name, age=18):\n",
70
+ " print('my name is %s, my age is %d' % (name, age))\n",
71
+ " \n",
72
+ "mytest('yasaka')\n",
73
+ "mytest('yasaka', 28)\n",
74
+ "mytest(name='yasaka', age=28)\n",
75
+ "mytest(age=28, name='yasaka')"
76
+ ]
77
+ },
78
+ {
79
+ "cell_type": "code",
80
+ "execution_count": 32,
81
+ "metadata": {},
82
+ "outputs": [
83
+ {
84
+ "name": "stdout",
85
+ "output_type": "stream",
86
+ "text": [
87
+ "my name is yasaka, my age is 19\n",
88
+ "() 0\n",
89
+ "my name is yasaka, my age is 19\n",
90
+ "('soccer', 'basketball', 'baseball') 3\n"
91
+ ]
92
+ }
93
+ ],
94
+ "source": [
95
+ "def mytest(name, age, *hobby):\n",
96
+ " print('my name is %s, my age is %d' % (name, age))\n",
97
+ " print(hobby, len(hobby))\n",
98
+ " \n",
99
+ "mytest('yasaka', 19)\n",
100
+ "mytest('yasaka', 19, 'soccer', 'basketball', 'baseball')"
101
+ ]
102
+ },
103
+ {
104
+ "cell_type": "code",
105
+ "execution_count": 33,
106
+ "metadata": {},
107
+ "outputs": [
108
+ {
109
+ "name": "stdout",
110
+ "output_type": "stream",
111
+ "text": [
112
+ "my name is yasaka, my age is 19\n",
113
+ "{} 0\n",
114
+ "my name is yasaka, my age is 19\n",
115
+ "{'fisrt_hobby': 'soccer', 'second_hobby': 'basketball', 'third_hobby': 'baseball'} 3\n"
116
+ ]
117
+ }
118
+ ],
119
+ "source": [
120
+ "def mytest(name, age, **hobby):\n",
121
+ " print('my name is %s, my age is %d' % (name, age))\n",
122
+ " print(hobby, len(hobby))\n",
123
+ " \n",
124
+ "mytest('yasaka', 19)\n",
125
+ "mytest('yasaka', 19, fisrt_hobby='soccer', second_hobby='basketball', third_hobby='baseball')"
126
+ ]
127
+ },
128
+ {
129
+ "cell_type": "code",
130
+ "execution_count": 11,
131
+ "metadata": {},
132
+ "outputs": [
133
+ {
134
+ "name": "stdout",
135
+ "output_type": "stream",
136
+ "text": [
137
+ "55\n",
138
+ "此方法是来将两个对象进行加和\n"
139
+ ]
140
+ }
141
+ ],
142
+ "source": [
143
+ "# 此方法是来将两个对象进行加和\n",
144
+ "def my_add(a, b):\n",
145
+ " \"\"\"此方法是来将两个对象进行加和\"\"\"\n",
146
+ " return a+b\n",
147
+ "\n",
148
+ "print(my_add(50, 5))\n",
149
+ "print(my_add.__doc__)"
150
+ ]
151
+ },
152
+ {
153
+ "cell_type": "code",
154
+ "execution_count": 12,
155
+ "metadata": {},
156
+ "outputs": [
157
+ {
158
+ "data": {
159
+ "text/plain": [
160
+ "150"
161
+ ]
162
+ },
163
+ "execution_count": 12,
164
+ "metadata": {},
165
+ "output_type": "execute_result"
166
+ }
167
+ ],
168
+ "source": [
169
+ "def func1(x):\n",
170
+ " y = 100\n",
171
+ " return x+y\n",
172
+ "\n",
173
+ "func1(50)"
174
+ ]
175
+ },
176
+ {
177
+ "cell_type": "code",
178
+ "execution_count": 18,
179
+ "metadata": {},
180
+ "outputs": [
181
+ {
182
+ "ename": "NameError",
183
+ "evalue": "name 'z' is not defined",
184
+ "output_type": "error",
185
+ "traceback": [
186
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
187
+ "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
188
+ "\u001b[1;32m<ipython-input-18-e0a3c1d18b6d>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mz\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 8\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfunc1\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m50\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfunc2\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m30\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
189
+ "\u001b[1;32m<ipython-input-18-e0a3c1d18b6d>\u001b[0m in \u001b[0;36mfunc2\u001b[1;34m(x)\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mfunc2\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 6\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m+\u001b[0m\u001b[0mz\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 7\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfunc1\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m50\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfunc2\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m30\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
190
+ "\u001b[1;31mNameError\u001b[0m: name 'z' is not defined"
191
+ ]
192
+ }
193
+ ],
194
+ "source": [
195
+ "def func1(x):\n",
196
+ " z = 100\n",
197
+ " return x+z\n",
198
+ "\n",
199
+ "def func2(x):\n",
200
+ " return x+z\n",
201
+ "\n",
202
+ "print(func1(50), func2(30))"
203
+ ]
204
+ },
205
+ {
206
+ "cell_type": "code",
207
+ "execution_count": 19,
208
+ "metadata": {},
209
+ "outputs": [
210
+ {
211
+ "name": "stdout",
212
+ "output_type": "stream",
213
+ "text": [
214
+ "150 130\n"
215
+ ]
216
+ }
217
+ ],
218
+ "source": [
219
+ "y = 100\n",
220
+ "\n",
221
+ "def func1(x):\n",
222
+ " return x+y\n",
223
+ "\n",
224
+ "def func2(x):\n",
225
+ " return x+y\n",
226
+ "\n",
227
+ "print(func1(50), func2(30))"
228
+ ]
229
+ },
230
+ {
231
+ "cell_type": "markdown",
232
+ "metadata": {},
233
+ "source": [
234
+ "就近原则"
235
+ ]
236
+ },
237
+ {
238
+ "cell_type": "code",
239
+ "execution_count": 20,
240
+ "metadata": {},
241
+ "outputs": [
242
+ {
243
+ "name": "stdout",
244
+ "output_type": "stream",
245
+ "text": [
246
+ "150 230\n"
247
+ ]
248
+ }
249
+ ],
250
+ "source": [
251
+ "y = 100\n",
252
+ "\n",
253
+ "def func1(x):\n",
254
+ " return x+y\n",
255
+ "\n",
256
+ "def func2(x):\n",
257
+ " y = 200\n",
258
+ " return x+y\n",
259
+ "\n",
260
+ "print(func1(50), func2(30))"
261
+ ]
262
+ },
263
+ {
264
+ "cell_type": "markdown",
265
+ "metadata": {},
266
+ "source": [
267
+ "global关键字\n",
268
+ "全局变量的访问或者说使用是直接可以去用的,不过要注意一下就近原则,才能确定是否真的访问到了你要的全局变量\n",
269
+ "全局变量的重新赋值,我们必须在函数内部去使用global关键字才可以"
270
+ ]
271
+ },
272
+ {
273
+ "cell_type": "code",
274
+ "execution_count": 23,
275
+ "metadata": {},
276
+ "outputs": [
277
+ {
278
+ "name": "stdout",
279
+ "output_type": "stream",
280
+ "text": [
281
+ "200\n"
282
+ ]
283
+ }
284
+ ],
285
+ "source": [
286
+ "y = 100\n",
287
+ "\n",
288
+ "def func():\n",
289
+ " global y\n",
290
+ " y = 200\n",
291
+ "\n",
292
+ "func()\n",
293
+ "print(y)"
294
+ ]
295
+ },
296
+ {
297
+ "cell_type": "markdown",
298
+ "metadata": {},
299
+ "source": [
300
+ "递归"
301
+ ]
302
+ },
303
+ {
304
+ "cell_type": "code",
305
+ "execution_count": 66,
306
+ "metadata": {},
307
+ "outputs": [
308
+ {
309
+ "name": "stdout",
310
+ "output_type": "stream",
311
+ "text": [
312
+ "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]\n"
313
+ ]
314
+ },
315
+ {
316
+ "data": {
317
+ "text/plain": [
318
+ "5050"
319
+ ]
320
+ },
321
+ "execution_count": 66,
322
+ "metadata": {},
323
+ "output_type": "execute_result"
324
+ }
325
+ ],
326
+ "source": [
327
+ "data = list(range(1, 101))\n",
328
+ "print(data)\n",
329
+ "\n",
330
+ "def my_add(a,b):\n",
331
+ " if len(a)==1:\n",
332
+ " return a[0]+b\n",
333
+ " return my_add(a[:-1] ,a[-1]) + b\n",
334
+ "\n",
335
+ "my_add(data[:-1], data[-1])"
336
+ ]
337
+ },
338
+ {
339
+ "cell_type": "code",
340
+ "execution_count": 35,
341
+ "metadata": {},
342
+ "outputs": [
343
+ {
344
+ "data": {
345
+ "text/plain": [
346
+ "[123, 45.67, -620000000.0, 123, 45.67, -620000000.0]"
347
+ ]
348
+ },
349
+ "execution_count": 35,
350
+ "metadata": {},
351
+ "output_type": "execute_result"
352
+ }
353
+ ],
354
+ "source": [
355
+ "myseq = [123, 45.67, -6.2e8]\n",
356
+ "\n",
357
+ "def mytest(num):\n",
358
+ " return num*2\n",
359
+ "\n",
360
+ "mytest(10)\n",
361
+ "mytest(myseq)"
362
+ ]
363
+ },
364
+ {
365
+ "cell_type": "markdown",
366
+ "metadata": {},
367
+ "source": [
368
+ "所谓高阶函数,就是不光可以传递变量,还可以传递函数\n",
369
+ "面向函数编程,说白了就是把函数传来传去,函数是第一要素\n",
370
+ "面向对象编程,说白了就是把对象传来传去,对象是第一要素"
371
+ ]
372
+ },
373
+ {
374
+ "cell_type": "code",
375
+ "execution_count": 38,
376
+ "metadata": {},
377
+ "outputs": [
378
+ {
379
+ "name": "stdout",
380
+ "output_type": "stream",
381
+ "text": [
382
+ "转换序列中的数值,要它们统一为一样的数值类型\n",
383
+ "转换序列中的数值,要它们统一为一样的数值类型\n",
384
+ "���换序列中的数值,要它们统一为一样的数值类型\n"
385
+ ]
386
+ },
387
+ {
388
+ "data": {
389
+ "text/plain": [
390
+ "[246, 91.34, -1240000000.0]"
391
+ ]
392
+ },
393
+ "execution_count": 38,
394
+ "metadata": {},
395
+ "output_type": "execute_result"
396
+ }
397
+ ],
398
+ "source": [
399
+ "myseq = [123, 45.67, -6.2e8]\n",
400
+ "\n",
401
+ "def convert(func, seq):\n",
402
+ " print('转换序列中的数值,要它们统一为一样的数值类型')\n",
403
+ " return [func(eachNum) for eachNum in seq]\n",
404
+ "\n",
405
+ "convert(int, myseq)\n",
406
+ "convert(float, myseq)\n",
407
+ "convert(mytest, myseq)"
408
+ ]
409
+ },
410
+ {
411
+ "cell_type": "code",
412
+ "execution_count": 72,
413
+ "metadata": {},
414
+ "outputs": [
415
+ {
416
+ "data": {
417
+ "text/plain": [
418
+ "[246, 91.34, -1240000000.0]"
419
+ ]
420
+ },
421
+ "execution_count": 72,
422
+ "metadata": {},
423
+ "output_type": "execute_result"
424
+ }
425
+ ],
426
+ "source": [
427
+ "list(map(mytest, myseq))"
428
+ ]
429
+ },
430
+ {
431
+ "cell_type": "code",
432
+ "execution_count": 83,
433
+ "metadata": {},
434
+ "outputs": [
435
+ {
436
+ "data": {
437
+ "text/plain": [
438
+ "[246, 91.34, -1240000000.0]"
439
+ ]
440
+ },
441
+ "execution_count": 83,
442
+ "metadata": {},
443
+ "output_type": "execute_result"
444
+ }
445
+ ],
446
+ "source": [
447
+ "list(map(lambda x: x*2, myseq))"
448
+ ]
449
+ },
450
+ {
451
+ "cell_type": "code",
452
+ "execution_count": 74,
453
+ "metadata": {},
454
+ "outputs": [
455
+ {
456
+ "name": "stdout",
457
+ "output_type": "stream",
458
+ "text": [
459
+ "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]\n"
460
+ ]
461
+ },
462
+ {
463
+ "data": {
464
+ "text/plain": [
465
+ "5050"
466
+ ]
467
+ },
468
+ "execution_count": 74,
469
+ "metadata": {},
470
+ "output_type": "execute_result"
471
+ }
472
+ ],
473
+ "source": [
474
+ "data = list(range(1, 101))\n",
475
+ "print(data)\n",
476
+ "from functools import reduce\n",
477
+ "\n",
478
+ "def my_add(a,b):\n",
479
+ " return a+b\n",
480
+ "\n",
481
+ "reduce(my_add, data)"
482
+ ]
483
+ },
484
+ {
485
+ "cell_type": "code",
486
+ "execution_count": 82,
487
+ "metadata": {},
488
+ "outputs": [
489
+ {
490
+ "name": "stdout",
491
+ "output_type": "stream",
492
+ "text": [
493
+ "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]\n"
494
+ ]
495
+ },
496
+ {
497
+ "data": {
498
+ "text/plain": [
499
+ "5050"
500
+ ]
501
+ },
502
+ "execution_count": 82,
503
+ "metadata": {},
504
+ "output_type": "execute_result"
505
+ }
506
+ ],
507
+ "source": [
508
+ "data = list(range(1, 101))\n",
509
+ "print(data)\n",
510
+ "from functools import reduce\n",
511
+ "reduce(lambda a,b: a+b , data)"
512
+ ]
513
+ },
514
+ {
515
+ "cell_type": "code",
516
+ "execution_count": 78,
517
+ "metadata": {},
518
+ "outputs": [
519
+ {
520
+ "name": "stdout",
521
+ "output_type": "stream",
522
+ "text": [
523
+ "[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100]\n"
524
+ ]
525
+ }
526
+ ],
527
+ "source": [
528
+ "def my_condition(x):\n",
529
+ " return x%2==0\n",
530
+ "\n",
531
+ "print(list(filter(my_condition, data)))"
532
+ ]
533
+ },
534
+ {
535
+ "cell_type": "code",
536
+ "execution_count": 81,
537
+ "metadata": {},
538
+ "outputs": [
539
+ {
540
+ "name": "stdout",
541
+ "output_type": "stream",
542
+ "text": [
543
+ "[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100]\n"
544
+ ]
545
+ }
546
+ ],
547
+ "source": [
548
+ "print(list(filter(lambda x: x%2==0, data)))"
549
+ ]
550
+ },
551
+ {
552
+ "cell_type": "code",
553
+ "execution_count": 80,
554
+ "metadata": {},
555
+ "outputs": [
556
+ {
557
+ "data": {
558
+ "text/plain": [
559
+ "[1, 3, 6, -20, -70]"
560
+ ]
561
+ },
562
+ "execution_count": 80,
563
+ "metadata": {},
564
+ "output_type": "execute_result"
565
+ }
566
+ ],
567
+ "source": [
568
+ "sorted([1,3,6,-20,-70],key=abs)"
569
+ ]
570
+ }
571
+ ],
572
+ "metadata": {
573
+ "kernelspec": {
574
+ "display_name": "Python 3",
575
+ "language": "python",
576
+ "name": "python3"
577
+ },
578
+ "language_info": {
579
+ "codemirror_mode": {
580
+ "name": "ipython",
581
+ "version": 3
582
+ },
583
+ "file_extension": ".py",
584
+ "mimetype": "text/x-python",
585
+ "name": "python",
586
+ "nbconvert_exporter": "python",
587
+ "pygments_lexer": "ipython3",
588
+ "version": "3.6.3"
589
+ }
590
+ },
591
+ "nbformat": 4,
592
+ "nbformat_minor": 2
593
+ }
python_list.ipynb ADDED
@@ -0,0 +1,643 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {
7
+ "collapsed": true
8
+ },
9
+ "outputs": [],
10
+ "source": [
11
+ "aList = [2 , 3, 1, 1, 2, 3, 'a string']"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": 4,
17
+ "metadata": {},
18
+ "outputs": [
19
+ {
20
+ "data": {
21
+ "text/plain": [
22
+ "[2, 3, 1, 1, 2, 3, 'a string']"
23
+ ]
24
+ },
25
+ "execution_count": 4,
26
+ "metadata": {},
27
+ "output_type": "execute_result"
28
+ }
29
+ ],
30
+ "source": [
31
+ "aList"
32
+ ]
33
+ },
34
+ {
35
+ "cell_type": "code",
36
+ "execution_count": 6,
37
+ "metadata": {},
38
+ "outputs": [
39
+ {
40
+ "data": {
41
+ "text/plain": [
42
+ "[2, 3, 1, 1, 2, 3, 'a string']"
43
+ ]
44
+ },
45
+ "execution_count": 6,
46
+ "metadata": {},
47
+ "output_type": "execute_result"
48
+ }
49
+ ],
50
+ "source": [
51
+ "aList = list([2 , 3, 1, 1, 2, 3, 'a string'])\n",
52
+ "aList"
53
+ ]
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "execution_count": 8,
58
+ "metadata": {},
59
+ "outputs": [
60
+ {
61
+ "ename": "TypeError",
62
+ "evalue": "'list' object is not callable",
63
+ "output_type": "error",
64
+ "traceback": [
65
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
66
+ "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
67
+ "\u001b[1;32m<ipython-input-8-88d62caf991b>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mlist\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mlist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m2\u001b[0m \u001b[1;33m,\u001b[0m \u001b[1;36m3\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m3\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'a string'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mlist\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
68
+ "\u001b[1;31mTypeError\u001b[0m: 'list' object is not callable"
69
+ ]
70
+ }
71
+ ],
72
+ "source": [
73
+ "list = list([2 , 3, 1, 1, 2, 3, 'a string'])\n",
74
+ "list"
75
+ ]
76
+ },
77
+ {
78
+ "cell_type": "markdown",
79
+ "metadata": {},
80
+ "source": [
81
+ "列表生成式"
82
+ ]
83
+ },
84
+ {
85
+ "cell_type": "code",
86
+ "execution_count": 9,
87
+ "metadata": {},
88
+ "outputs": [
89
+ {
90
+ "data": {
91
+ "text/plain": [
92
+ "['a', 'b', 'c', 'd', 'e', 'f', 'g']"
93
+ ]
94
+ },
95
+ "execution_count": 9,
96
+ "metadata": {},
97
+ "output_type": "execute_result"
98
+ }
99
+ ],
100
+ "source": [
101
+ "[x for x in \"abcdefg\"]"
102
+ ]
103
+ },
104
+ {
105
+ "cell_type": "code",
106
+ "execution_count": 10,
107
+ "metadata": {},
108
+ "outputs": [
109
+ {
110
+ "data": {
111
+ "text/plain": [
112
+ "['a', 'b', 'c', 'd', 'e', 'f', 'g']"
113
+ ]
114
+ },
115
+ "execution_count": 10,
116
+ "metadata": {},
117
+ "output_type": "execute_result"
118
+ }
119
+ ],
120
+ "source": [
121
+ "aList = []\n",
122
+ "for x in 'abcdefg':\n",
123
+ " aList.append(x)\n",
124
+ " \n",
125
+ "aList"
126
+ ]
127
+ },
128
+ {
129
+ "cell_type": "code",
130
+ "execution_count": 11,
131
+ "metadata": {},
132
+ "outputs": [
133
+ {
134
+ "data": {
135
+ "text/plain": [
136
+ "[2, 4, 6, 8]"
137
+ ]
138
+ },
139
+ "execution_count": 11,
140
+ "metadata": {},
141
+ "output_type": "execute_result"
142
+ }
143
+ ],
144
+ "source": [
145
+ "[x*2 for x in range(1,5)]"
146
+ ]
147
+ },
148
+ {
149
+ "cell_type": "code",
150
+ "execution_count": 12,
151
+ "metadata": {},
152
+ "outputs": [
153
+ {
154
+ "data": {
155
+ "text/plain": [
156
+ "[10, 20, 30]"
157
+ ]
158
+ },
159
+ "execution_count": 12,
160
+ "metadata": {},
161
+ "output_type": "execute_result"
162
+ }
163
+ ],
164
+ "source": [
165
+ "[x*2 for x in range(1,20) if x%5==0]"
166
+ ]
167
+ },
168
+ {
169
+ "cell_type": "code",
170
+ "execution_count": 13,
171
+ "metadata": {},
172
+ "outputs": [
173
+ {
174
+ "data": {
175
+ "text/plain": [
176
+ "[10, 20, 30, 40, 50]"
177
+ ]
178
+ },
179
+ "execution_count": 13,
180
+ "metadata": {},
181
+ "output_type": "execute_result"
182
+ }
183
+ ],
184
+ "source": [
185
+ "a = [10, 20 ,30]\n",
186
+ "b = [40, 50]\n",
187
+ "a + b"
188
+ ]
189
+ },
190
+ {
191
+ "cell_type": "code",
192
+ "execution_count": 14,
193
+ "metadata": {
194
+ "collapsed": true
195
+ },
196
+ "outputs": [],
197
+ "source": [
198
+ "a = [10, 20 ,30]\n",
199
+ "b = [40, 50]\n",
200
+ "a.extend(b)"
201
+ ]
202
+ },
203
+ {
204
+ "cell_type": "code",
205
+ "execution_count": 15,
206
+ "metadata": {},
207
+ "outputs": [
208
+ {
209
+ "data": {
210
+ "text/plain": [
211
+ "[10, 20, 30, 40, 50]"
212
+ ]
213
+ },
214
+ "execution_count": 15,
215
+ "metadata": {},
216
+ "output_type": "execute_result"
217
+ }
218
+ ],
219
+ "source": [
220
+ "a"
221
+ ]
222
+ },
223
+ {
224
+ "cell_type": "code",
225
+ "execution_count": 16,
226
+ "metadata": {},
227
+ "outputs": [
228
+ {
229
+ "data": {
230
+ "text/plain": [
231
+ "1"
232
+ ]
233
+ },
234
+ "execution_count": 16,
235
+ "metadata": {},
236
+ "output_type": "execute_result"
237
+ }
238
+ ],
239
+ "source": [
240
+ "a = [10,20,30,40,50,20,30,20,30]\n",
241
+ "a.index(20)"
242
+ ]
243
+ },
244
+ {
245
+ "cell_type": "code",
246
+ "execution_count": 18,
247
+ "metadata": {},
248
+ "outputs": [
249
+ {
250
+ "data": {
251
+ "text/plain": [
252
+ "5"
253
+ ]
254
+ },
255
+ "execution_count": 18,
256
+ "metadata": {},
257
+ "output_type": "execute_result"
258
+ }
259
+ ],
260
+ "source": [
261
+ "a.index(20, 3)"
262
+ ]
263
+ },
264
+ {
265
+ "cell_type": "code",
266
+ "execution_count": 21,
267
+ "metadata": {},
268
+ "outputs": [
269
+ {
270
+ "data": {
271
+ "text/plain": [
272
+ "[10, 5000, 30, 40, 50, 20, 30, 20, 30]"
273
+ ]
274
+ },
275
+ "execution_count": 21,
276
+ "metadata": {},
277
+ "output_type": "execute_result"
278
+ }
279
+ ],
280
+ "source": [
281
+ "a[1] = 5000\n",
282
+ "a"
283
+ ]
284
+ },
285
+ {
286
+ "cell_type": "code",
287
+ "execution_count": 22,
288
+ "metadata": {
289
+ "collapsed": true
290
+ },
291
+ "outputs": [],
292
+ "source": [
293
+ "del a[1]"
294
+ ]
295
+ },
296
+ {
297
+ "cell_type": "code",
298
+ "execution_count": 23,
299
+ "metadata": {},
300
+ "outputs": [
301
+ {
302
+ "data": {
303
+ "text/plain": [
304
+ "[10, 30, 40, 50, 20, 30, 20, 30]"
305
+ ]
306
+ },
307
+ "execution_count": 23,
308
+ "metadata": {},
309
+ "output_type": "execute_result"
310
+ }
311
+ ],
312
+ "source": [
313
+ "a"
314
+ ]
315
+ },
316
+ {
317
+ "cell_type": "code",
318
+ "execution_count": 24,
319
+ "metadata": {
320
+ "collapsed": true
321
+ },
322
+ "outputs": [],
323
+ "source": [
324
+ "del a"
325
+ ]
326
+ },
327
+ {
328
+ "cell_type": "code",
329
+ "execution_count": 25,
330
+ "metadata": {},
331
+ "outputs": [
332
+ {
333
+ "ename": "NameError",
334
+ "evalue": "name 'a' is not defined",
335
+ "output_type": "error",
336
+ "traceback": [
337
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
338
+ "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)",
339
+ "\u001b[1;32m<ipython-input-25-60b725f10c9c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
340
+ "\u001b[1;31mNameError\u001b[0m: name 'a' is not defined"
341
+ ]
342
+ }
343
+ ],
344
+ "source": [
345
+ "a"
346
+ ]
347
+ },
348
+ {
349
+ "cell_type": "code",
350
+ "execution_count": 26,
351
+ "metadata": {
352
+ "collapsed": true
353
+ },
354
+ "outputs": [],
355
+ "source": [
356
+ "a=[1,2,3,4,5,6]"
357
+ ]
358
+ },
359
+ {
360
+ "cell_type": "code",
361
+ "execution_count": 27,
362
+ "metadata": {},
363
+ "outputs": [
364
+ {
365
+ "data": {
366
+ "text/plain": [
367
+ "6"
368
+ ]
369
+ },
370
+ "execution_count": 27,
371
+ "metadata": {},
372
+ "output_type": "execute_result"
373
+ }
374
+ ],
375
+ "source": [
376
+ "a.pop()"
377
+ ]
378
+ },
379
+ {
380
+ "cell_type": "code",
381
+ "execution_count": 29,
382
+ "metadata": {},
383
+ "outputs": [
384
+ {
385
+ "data": {
386
+ "text/plain": [
387
+ "[1, 2, 3, 4, 5]"
388
+ ]
389
+ },
390
+ "execution_count": 29,
391
+ "metadata": {},
392
+ "output_type": "execute_result"
393
+ }
394
+ ],
395
+ "source": [
396
+ "a"
397
+ ]
398
+ },
399
+ {
400
+ "cell_type": "code",
401
+ "execution_count": 30,
402
+ "metadata": {},
403
+ "outputs": [
404
+ {
405
+ "data": {
406
+ "text/plain": [
407
+ "3"
408
+ ]
409
+ },
410
+ "execution_count": 30,
411
+ "metadata": {},
412
+ "output_type": "execute_result"
413
+ }
414
+ ],
415
+ "source": [
416
+ "a.pop(2)"
417
+ ]
418
+ },
419
+ {
420
+ "cell_type": "code",
421
+ "execution_count": 31,
422
+ "metadata": {
423
+ "collapsed": true
424
+ },
425
+ "outputs": [],
426
+ "source": [
427
+ "a = [10,20,30,40,50,20,30,20,30]\n",
428
+ "a.remove(20)"
429
+ ]
430
+ },
431
+ {
432
+ "cell_type": "code",
433
+ "execution_count": 32,
434
+ "metadata": {},
435
+ "outputs": [
436
+ {
437
+ "data": {
438
+ "text/plain": [
439
+ "[10, 30, 40, 50, 20, 30, 20, 30]"
440
+ ]
441
+ },
442
+ "execution_count": 32,
443
+ "metadata": {},
444
+ "output_type": "execute_result"
445
+ }
446
+ ],
447
+ "source": [
448
+ "a"
449
+ ]
450
+ },
451
+ {
452
+ "cell_type": "code",
453
+ "execution_count": 33,
454
+ "metadata": {},
455
+ "outputs": [
456
+ {
457
+ "data": {
458
+ "text/plain": [
459
+ "'##########'"
460
+ ]
461
+ },
462
+ "execution_count": 33,
463
+ "metadata": {},
464
+ "output_type": "execute_result"
465
+ }
466
+ ],
467
+ "source": [
468
+ "'#' * 10"
469
+ ]
470
+ },
471
+ {
472
+ "cell_type": "code",
473
+ "execution_count": 36,
474
+ "metadata": {},
475
+ "outputs": [
476
+ {
477
+ "data": {
478
+ "text/plain": [
479
+ "(6, 60, 10)"
480
+ ]
481
+ },
482
+ "execution_count": 36,
483
+ "metadata": {},
484
+ "output_type": "execute_result"
485
+ }
486
+ ],
487
+ "source": [
488
+ "a=[10,20,30,40,50,60]\n",
489
+ "len(a), max(a), min(a)"
490
+ ]
491
+ },
492
+ {
493
+ "cell_type": "code",
494
+ "execution_count": 38,
495
+ "metadata": {},
496
+ "outputs": [
497
+ {
498
+ "data": {
499
+ "text/plain": [
500
+ "([10, 20, 30], [10, 5000, 30])"
501
+ ]
502
+ },
503
+ "execution_count": 38,
504
+ "metadata": {},
505
+ "output_type": "execute_result"
506
+ }
507
+ ],
508
+ "source": [
509
+ "aa=[10,20,30]\n",
510
+ "bb=aa.copy()\n",
511
+ "bb[1] = 5000\n",
512
+ "aa, bb"
513
+ ]
514
+ },
515
+ {
516
+ "cell_type": "code",
517
+ "execution_count": 39,
518
+ "metadata": {},
519
+ "outputs": [
520
+ {
521
+ "data": {
522
+ "text/plain": [
523
+ "([10, 5000, 30], [10, 5000, 30])"
524
+ ]
525
+ },
526
+ "execution_count": 39,
527
+ "metadata": {},
528
+ "output_type": "execute_result"
529
+ }
530
+ ],
531
+ "source": [
532
+ "aa = [10, 20, 30]\n",
533
+ "bb = aa\n",
534
+ "bb[1] = 5000\n",
535
+ "aa, bb"
536
+ ]
537
+ },
538
+ {
539
+ "cell_type": "code",
540
+ "execution_count": 43,
541
+ "metadata": {},
542
+ "outputs": [
543
+ {
544
+ "data": {
545
+ "text/plain": [
546
+ "3"
547
+ ]
548
+ },
549
+ "execution_count": 43,
550
+ "metadata": {},
551
+ "output_type": "execute_result"
552
+ }
553
+ ],
554
+ "source": [
555
+ "a=[10,20,40,30,10,20,50,10]\n",
556
+ "a.count(10)"
557
+ ]
558
+ },
559
+ {
560
+ "cell_type": "code",
561
+ "execution_count": 46,
562
+ "metadata": {},
563
+ "outputs": [
564
+ {
565
+ "data": {
566
+ "text/plain": [
567
+ "[36, 34, 20, 17, 13, 11, 5]"
568
+ ]
569
+ },
570
+ "execution_count": 46,
571
+ "metadata": {},
572
+ "output_type": "execute_result"
573
+ }
574
+ ],
575
+ "source": [
576
+ "a=[11,20,13,34,5,36,17]\n",
577
+ "a.sort(reverse=True)\n",
578
+ "a"
579
+ ]
580
+ },
581
+ {
582
+ "cell_type": "code",
583
+ "execution_count": 48,
584
+ "metadata": {},
585
+ "outputs": [
586
+ {
587
+ "data": {
588
+ "text/plain": [
589
+ "([5, 11, 13, 17, 20, 34, 36], [36, 34, 20, 17, 13, 11, 5])"
590
+ ]
591
+ },
592
+ "execution_count": 48,
593
+ "metadata": {},
594
+ "output_type": "execute_result"
595
+ }
596
+ ],
597
+ "source": [
598
+ "sorted(a), a"
599
+ ]
600
+ },
601
+ {
602
+ "cell_type": "code",
603
+ "execution_count": 49,
604
+ "metadata": {},
605
+ "outputs": [
606
+ {
607
+ "data": {
608
+ "text/plain": [
609
+ "[36, 34, 20, 17, 13, 11, 5]"
610
+ ]
611
+ },
612
+ "execution_count": 49,
613
+ "metadata": {},
614
+ "output_type": "execute_result"
615
+ }
616
+ ],
617
+ "source": [
618
+ "sorted(a, key=lambda x: -x)"
619
+ ]
620
+ }
621
+ ],
622
+ "metadata": {
623
+ "kernelspec": {
624
+ "display_name": "Python 3",
625
+ "language": "python",
626
+ "name": "python3"
627
+ },
628
+ "language_info": {
629
+ "codemirror_mode": {
630
+ "name": "ipython",
631
+ "version": 3
632
+ },
633
+ "file_extension": ".py",
634
+ "mimetype": "text/x-python",
635
+ "name": "python",
636
+ "nbconvert_exporter": "python",
637
+ "pygments_lexer": "ipython3",
638
+ "version": "3.6.3"
639
+ }
640
+ },
641
+ "nbformat": 4,
642
+ "nbformat_minor": 2
643
+ }
python_numpy_array_arange_random.ipynb ADDED
@@ -0,0 +1,946 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {
7
+ "collapsed": true
8
+ },
9
+ "outputs": [],
10
+ "source": [
11
+ "import numpy as np"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": 3,
17
+ "metadata": {},
18
+ "outputs": [
19
+ {
20
+ "data": {
21
+ "text/plain": [
22
+ "array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
23
+ ]
24
+ },
25
+ "execution_count": 3,
26
+ "metadata": {},
27
+ "output_type": "execute_result"
28
+ }
29
+ ],
30
+ "source": [
31
+ "np.arange(10)"
32
+ ]
33
+ },
34
+ {
35
+ "cell_type": "code",
36
+ "execution_count": 4,
37
+ "metadata": {},
38
+ "outputs": [
39
+ {
40
+ "data": {
41
+ "text/plain": [
42
+ "numpy.ndarray"
43
+ ]
44
+ },
45
+ "execution_count": 4,
46
+ "metadata": {},
47
+ "output_type": "execute_result"
48
+ }
49
+ ],
50
+ "source": [
51
+ "type(np.arange(10))"
52
+ ]
53
+ },
54
+ {
55
+ "cell_type": "code",
56
+ "execution_count": 5,
57
+ "metadata": {},
58
+ "outputs": [
59
+ {
60
+ "data": {
61
+ "text/plain": [
62
+ "(10,)"
63
+ ]
64
+ },
65
+ "execution_count": 5,
66
+ "metadata": {},
67
+ "output_type": "execute_result"
68
+ }
69
+ ],
70
+ "source": [
71
+ "arr = np.arange(10)\n",
72
+ "arr.shape"
73
+ ]
74
+ },
75
+ {
76
+ "cell_type": "code",
77
+ "execution_count": 6,
78
+ "metadata": {},
79
+ "outputs": [
80
+ {
81
+ "data": {
82
+ "text/plain": [
83
+ "10"
84
+ ]
85
+ },
86
+ "execution_count": 6,
87
+ "metadata": {},
88
+ "output_type": "execute_result"
89
+ }
90
+ ],
91
+ "source": [
92
+ "arr.shape[0]"
93
+ ]
94
+ },
95
+ {
96
+ "cell_type": "code",
97
+ "execution_count": 7,
98
+ "metadata": {},
99
+ "outputs": [
100
+ {
101
+ "data": {
102
+ "text/plain": [
103
+ "array([1, 2, 3, 4, 5])"
104
+ ]
105
+ },
106
+ "execution_count": 7,
107
+ "metadata": {},
108
+ "output_type": "execute_result"
109
+ }
110
+ ],
111
+ "source": [
112
+ "np.array([1,2,3,4,5])"
113
+ ]
114
+ },
115
+ {
116
+ "cell_type": "code",
117
+ "execution_count": 8,
118
+ "metadata": {},
119
+ "outputs": [
120
+ {
121
+ "ename": "AttributeError",
122
+ "evalue": "'list' object has no attribute 'shape'",
123
+ "output_type": "error",
124
+ "traceback": [
125
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
126
+ "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
127
+ "\u001b[1;32m<ipython-input-8-6a829e60bb92>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[0mmy_list\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 2\u001b[1;33m \u001b[0mmy_list\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshape\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
128
+ "\u001b[1;31mAttributeError\u001b[0m: 'list' object has no attribute 'shape'"
129
+ ]
130
+ }
131
+ ],
132
+ "source": [
133
+ "my_list = [1,2,3,4,5]\n",
134
+ "my_list.shape"
135
+ ]
136
+ },
137
+ {
138
+ "cell_type": "code",
139
+ "execution_count": 9,
140
+ "metadata": {},
141
+ "outputs": [
142
+ {
143
+ "data": {
144
+ "text/plain": [
145
+ "(5,)"
146
+ ]
147
+ },
148
+ "execution_count": 9,
149
+ "metadata": {},
150
+ "output_type": "execute_result"
151
+ }
152
+ ],
153
+ "source": [
154
+ "arr = np.array(my_list)\n",
155
+ "arr.shape"
156
+ ]
157
+ },
158
+ {
159
+ "cell_type": "code",
160
+ "execution_count": 10,
161
+ "metadata": {},
162
+ "outputs": [
163
+ {
164
+ "data": {
165
+ "text/plain": [
166
+ "(3, 3)"
167
+ ]
168
+ },
169
+ "execution_count": 10,
170
+ "metadata": {},
171
+ "output_type": "execute_result"
172
+ }
173
+ ],
174
+ "source": [
175
+ "arr = np.array([[1,2,3],[4,5,6],[7,8,9]])\n",
176
+ "arr.shape"
177
+ ]
178
+ },
179
+ {
180
+ "cell_type": "code",
181
+ "execution_count": 11,
182
+ "metadata": {},
183
+ "outputs": [
184
+ {
185
+ "data": {
186
+ "text/plain": [
187
+ "array([[1, 2, 3],\n",
188
+ " [4, 5, 6],\n",
189
+ " [7, 8, 9]])"
190
+ ]
191
+ },
192
+ "execution_count": 11,
193
+ "metadata": {},
194
+ "output_type": "execute_result"
195
+ }
196
+ ],
197
+ "source": [
198
+ "arr"
199
+ ]
200
+ },
201
+ {
202
+ "cell_type": "code",
203
+ "execution_count": 14,
204
+ "metadata": {},
205
+ "outputs": [
206
+ {
207
+ "data": {
208
+ "text/plain": [
209
+ "(1, 1, 5)"
210
+ ]
211
+ },
212
+ "execution_count": 14,
213
+ "metadata": {},
214
+ "output_type": "execute_result"
215
+ }
216
+ ],
217
+ "source": [
218
+ "arr = np.array([1,2,3,4,5], ndmin=3)\n",
219
+ "arr.shape"
220
+ ]
221
+ },
222
+ {
223
+ "cell_type": "code",
224
+ "execution_count": 15,
225
+ "metadata": {},
226
+ "outputs": [
227
+ {
228
+ "data": {
229
+ "text/plain": [
230
+ "array([[[1, 2, 3, 4, 5]]])"
231
+ ]
232
+ },
233
+ "execution_count": 15,
234
+ "metadata": {},
235
+ "output_type": "execute_result"
236
+ }
237
+ ],
238
+ "source": [
239
+ "arr"
240
+ ]
241
+ },
242
+ {
243
+ "cell_type": "code",
244
+ "execution_count": 16,
245
+ "metadata": {},
246
+ "outputs": [
247
+ {
248
+ "data": {
249
+ "text/plain": [
250
+ "array([1., 2., 3., 4., 5.])"
251
+ ]
252
+ },
253
+ "execution_count": 16,
254
+ "metadata": {},
255
+ "output_type": "execute_result"
256
+ }
257
+ ],
258
+ "source": [
259
+ "arr = np.array([1,2,3,4,5],dtype=float)\n",
260
+ "arr"
261
+ ]
262
+ },
263
+ {
264
+ "cell_type": "code",
265
+ "execution_count": 19,
266
+ "metadata": {},
267
+ "outputs": [
268
+ {
269
+ "data": {
270
+ "text/plain": [
271
+ "array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.])"
272
+ ]
273
+ },
274
+ "execution_count": 19,
275
+ "metadata": {},
276
+ "output_type": "execute_result"
277
+ }
278
+ ],
279
+ "source": [
280
+ "np.arange(10.5)"
281
+ ]
282
+ },
283
+ {
284
+ "cell_type": "code",
285
+ "execution_count": 22,
286
+ "metadata": {},
287
+ "outputs": [
288
+ {
289
+ "data": {
290
+ "text/plain": [
291
+ "array([1., 3., 5., 7., 9.])"
292
+ ]
293
+ },
294
+ "execution_count": 22,
295
+ "metadata": {},
296
+ "output_type": "execute_result"
297
+ }
298
+ ],
299
+ "source": [
300
+ "np.arange(1,10,2, dtype=float)"
301
+ ]
302
+ },
303
+ {
304
+ "cell_type": "code",
305
+ "execution_count": 23,
306
+ "metadata": {},
307
+ "outputs": [
308
+ {
309
+ "data": {
310
+ "text/plain": [
311
+ "(3, 3)"
312
+ ]
313
+ },
314
+ "execution_count": 23,
315
+ "metadata": {},
316
+ "output_type": "execute_result"
317
+ }
318
+ ],
319
+ "source": [
320
+ "b=np.array([np.arange(1,4),np.arange(4,7),np.arange(7,10)])\n",
321
+ "b.shape"
322
+ ]
323
+ },
324
+ {
325
+ "cell_type": "code",
326
+ "execution_count": 24,
327
+ "metadata": {},
328
+ "outputs": [
329
+ {
330
+ "data": {
331
+ "text/plain": [
332
+ "array([[1, 2, 3],\n",
333
+ " [4, 5, 6],\n",
334
+ " [7, 8, 9]])"
335
+ ]
336
+ },
337
+ "execution_count": 24,
338
+ "metadata": {},
339
+ "output_type": "execute_result"
340
+ }
341
+ ],
342
+ "source": [
343
+ "b"
344
+ ]
345
+ },
346
+ {
347
+ "cell_type": "code",
348
+ "execution_count": 27,
349
+ "metadata": {},
350
+ "outputs": [
351
+ {
352
+ "data": {
353
+ "text/plain": [
354
+ "array([0.10289107, 0.7626481 , 0.57774218, 0.55252354, 0.51513559,\n",
355
+ " 0.55679949, 0.22482356, 0.05471953, 0.22847806, 0.64784352])"
356
+ ]
357
+ },
358
+ "execution_count": 27,
359
+ "metadata": {},
360
+ "output_type": "execute_result"
361
+ }
362
+ ],
363
+ "source": [
364
+ "arr = np.random.random(size=10)\n",
365
+ "arr"
366
+ ]
367
+ },
368
+ {
369
+ "cell_type": "code",
370
+ "execution_count": 28,
371
+ "metadata": {},
372
+ "outputs": [
373
+ {
374
+ "data": {
375
+ "text/plain": [
376
+ "(10,)"
377
+ ]
378
+ },
379
+ "execution_count": 28,
380
+ "metadata": {},
381
+ "output_type": "execute_result"
382
+ }
383
+ ],
384
+ "source": [
385
+ "arr.shape"
386
+ ]
387
+ },
388
+ {
389
+ "cell_type": "code",
390
+ "execution_count": 29,
391
+ "metadata": {},
392
+ "outputs": [
393
+ {
394
+ "data": {
395
+ "text/plain": [
396
+ "array([[0.07525423, 0.23016941, 0.18855109, 0.7965775 ],\n",
397
+ " [0.83462746, 0.4501435 , 0.4985075 , 0.80113762],\n",
398
+ " [0.43671224, 0.76218594, 0.6482414 , 0.29685941]])"
399
+ ]
400
+ },
401
+ "execution_count": 29,
402
+ "metadata": {},
403
+ "output_type": "execute_result"
404
+ }
405
+ ],
406
+ "source": [
407
+ "arr = np.random.random(size=(3,4))\n",
408
+ "arr"
409
+ ]
410
+ },
411
+ {
412
+ "cell_type": "code",
413
+ "execution_count": 31,
414
+ "metadata": {},
415
+ "outputs": [
416
+ {
417
+ "data": {
418
+ "text/plain": [
419
+ "array([2, 5, 7, 3, 3, 9, 2, 0, 4, 2])"
420
+ ]
421
+ },
422
+ "execution_count": 31,
423
+ "metadata": {},
424
+ "output_type": "execute_result"
425
+ }
426
+ ],
427
+ "source": [
428
+ "arr = np.random.randint(10,size=10)\n",
429
+ "arr"
430
+ ]
431
+ },
432
+ {
433
+ "cell_type": "code",
434
+ "execution_count": 34,
435
+ "metadata": {},
436
+ "outputs": [
437
+ {
438
+ "data": {
439
+ "text/plain": [
440
+ "array([9, 7, 9, 6, 5, 6, 5, 6, 5, 9])"
441
+ ]
442
+ },
443
+ "execution_count": 34,
444
+ "metadata": {},
445
+ "output_type": "execute_result"
446
+ }
447
+ ],
448
+ "source": [
449
+ "arr = np.random.randint(5,10, size=10)\n",
450
+ "arr"
451
+ ]
452
+ },
453
+ {
454
+ "cell_type": "code",
455
+ "execution_count": 35,
456
+ "metadata": {},
457
+ "outputs": [
458
+ {
459
+ "data": {
460
+ "text/plain": [
461
+ "array([[5, 6, 5, 8],\n",
462
+ " [7, 9, 6, 9],\n",
463
+ " [8, 8, 5, 9]])"
464
+ ]
465
+ },
466
+ "execution_count": 35,
467
+ "metadata": {},
468
+ "output_type": "execute_result"
469
+ }
470
+ ],
471
+ "source": [
472
+ "arr = np.random.randint(5,10, size=(3,4))\n",
473
+ "arr"
474
+ ]
475
+ },
476
+ {
477
+ "cell_type": "code",
478
+ "execution_count": 37,
479
+ "metadata": {},
480
+ "outputs": [
481
+ {
482
+ "data": {
483
+ "text/plain": [
484
+ "0.19650183392918344"
485
+ ]
486
+ },
487
+ "execution_count": 37,
488
+ "metadata": {},
489
+ "output_type": "execute_result"
490
+ }
491
+ ],
492
+ "source": [
493
+ "np.random.randn()"
494
+ ]
495
+ },
496
+ {
497
+ "cell_type": "code",
498
+ "execution_count": 38,
499
+ "metadata": {},
500
+ "outputs": [
501
+ {
502
+ "data": {
503
+ "text/plain": [
504
+ "array([[ 1.69537671, 0.99040676, 0.32886744],\n",
505
+ " [ 0.26155432, -0.42947806, 1.76046921]])"
506
+ ]
507
+ },
508
+ "execution_count": 38,
509
+ "metadata": {},
510
+ "output_type": "execute_result"
511
+ }
512
+ ],
513
+ "source": [
514
+ "np.random.randn(2,3)"
515
+ ]
516
+ },
517
+ {
518
+ "cell_type": "code",
519
+ "execution_count": 39,
520
+ "metadata": {},
521
+ "outputs": [
522
+ {
523
+ "data": {
524
+ "text/plain": [
525
+ "array([[[-1.6688893 , 0.55980063, 0.64526982, 0.92446168],\n",
526
+ " [ 0.07731325, 1.29017537, 1.34607326, 0.67274209],\n",
527
+ " [-0.84949688, -1.48586461, 1.33580643, -1.32477716]],\n",
528
+ "\n",
529
+ " [[ 1.66791093, -0.28708473, -0.8955759 , -1.54500502],\n",
530
+ " [-0.0609652 , 0.15746865, -0.9026866 , 0.59799998],\n",
531
+ " [-0.66692313, -1.06136765, 0.08684277, 1.25851734]]])"
532
+ ]
533
+ },
534
+ "execution_count": 39,
535
+ "metadata": {},
536
+ "output_type": "execute_result"
537
+ }
538
+ ],
539
+ "source": [
540
+ "np.random.randn(2,3,4)"
541
+ ]
542
+ },
543
+ {
544
+ "cell_type": "code",
545
+ "execution_count": 42,
546
+ "metadata": {
547
+ "collapsed": true
548
+ },
549
+ "outputs": [],
550
+ "source": [
551
+ "np.random.seed(42)"
552
+ ]
553
+ },
554
+ {
555
+ "cell_type": "code",
556
+ "execution_count": 43,
557
+ "metadata": {},
558
+ "outputs": [
559
+ {
560
+ "data": {
561
+ "text/plain": [
562
+ "0.4967141530112327"
563
+ ]
564
+ },
565
+ "execution_count": 43,
566
+ "metadata": {},
567
+ "output_type": "execute_result"
568
+ }
569
+ ],
570
+ "source": [
571
+ "np.random.randn()"
572
+ ]
573
+ },
574
+ {
575
+ "cell_type": "code",
576
+ "execution_count": 44,
577
+ "metadata": {},
578
+ "outputs": [
579
+ {
580
+ "data": {
581
+ "text/plain": [
582
+ "array([1, 2, 3, 4, 5])"
583
+ ]
584
+ },
585
+ "execution_count": 44,
586
+ "metadata": {},
587
+ "output_type": "execute_result"
588
+ }
589
+ ],
590
+ "source": [
591
+ "arr = np.array([1,2,3,4,5])\n",
592
+ "arr"
593
+ ]
594
+ },
595
+ {
596
+ "cell_type": "code",
597
+ "execution_count": 45,
598
+ "metadata": {
599
+ "collapsed": true
600
+ },
601
+ "outputs": [],
602
+ "source": [
603
+ "np.random.shuffle(arr)"
604
+ ]
605
+ },
606
+ {
607
+ "cell_type": "code",
608
+ "execution_count": 46,
609
+ "metadata": {},
610
+ "outputs": [
611
+ {
612
+ "data": {
613
+ "text/plain": [
614
+ "array([2, 5, 1, 4, 3])"
615
+ ]
616
+ },
617
+ "execution_count": 46,
618
+ "metadata": {},
619
+ "output_type": "execute_result"
620
+ }
621
+ ],
622
+ "source": [
623
+ "arr"
624
+ ]
625
+ },
626
+ {
627
+ "cell_type": "code",
628
+ "execution_count": 47,
629
+ "metadata": {},
630
+ "outputs": [
631
+ {
632
+ "data": {
633
+ "text/plain": [
634
+ "1"
635
+ ]
636
+ },
637
+ "execution_count": 47,
638
+ "metadata": {},
639
+ "output_type": "execute_result"
640
+ }
641
+ ],
642
+ "source": [
643
+ "arr.ndim"
644
+ ]
645
+ },
646
+ {
647
+ "cell_type": "code",
648
+ "execution_count": 48,
649
+ "metadata": {},
650
+ "outputs": [
651
+ {
652
+ "data": {
653
+ "text/plain": [
654
+ "(5,)"
655
+ ]
656
+ },
657
+ "execution_count": 48,
658
+ "metadata": {},
659
+ "output_type": "execute_result"
660
+ }
661
+ ],
662
+ "source": [
663
+ "arr.shape"
664
+ ]
665
+ },
666
+ {
667
+ "cell_type": "code",
668
+ "execution_count": 49,
669
+ "metadata": {},
670
+ "outputs": [
671
+ {
672
+ "data": {
673
+ "text/plain": [
674
+ "5"
675
+ ]
676
+ },
677
+ "execution_count": 49,
678
+ "metadata": {},
679
+ "output_type": "execute_result"
680
+ }
681
+ ],
682
+ "source": [
683
+ "arr.size"
684
+ ]
685
+ },
686
+ {
687
+ "cell_type": "code",
688
+ "execution_count": 50,
689
+ "metadata": {},
690
+ "outputs": [
691
+ {
692
+ "data": {
693
+ "text/plain": [
694
+ "dtype('int32')"
695
+ ]
696
+ },
697
+ "execution_count": 50,
698
+ "metadata": {},
699
+ "output_type": "execute_result"
700
+ }
701
+ ],
702
+ "source": [
703
+ "arr.dtype"
704
+ ]
705
+ },
706
+ {
707
+ "cell_type": "code",
708
+ "execution_count": 51,
709
+ "metadata": {},
710
+ "outputs": [
711
+ {
712
+ "data": {
713
+ "text/plain": [
714
+ "array([[0., 0., 0., 0.],\n",
715
+ " [0., 0., 0., 0.],\n",
716
+ " [0., 0., 0., 0.]])"
717
+ ]
718
+ },
719
+ "execution_count": 51,
720
+ "metadata": {},
721
+ "output_type": "execute_result"
722
+ }
723
+ ],
724
+ "source": [
725
+ "np.zeros((3,4))"
726
+ ]
727
+ },
728
+ {
729
+ "cell_type": "code",
730
+ "execution_count": 52,
731
+ "metadata": {},
732
+ "outputs": [
733
+ {
734
+ "data": {
735
+ "text/plain": [
736
+ "array([[1., 1., 1.],\n",
737
+ " [1., 1., 1.]])"
738
+ ]
739
+ },
740
+ "execution_count": 52,
741
+ "metadata": {},
742
+ "output_type": "execute_result"
743
+ }
744
+ ],
745
+ "source": [
746
+ "np.ones((2,3))"
747
+ ]
748
+ },
749
+ {
750
+ "cell_type": "code",
751
+ "execution_count": 53,
752
+ "metadata": {},
753
+ "outputs": [
754
+ {
755
+ "data": {
756
+ "text/plain": [
757
+ "array([[0., 0., 0., 0.],\n",
758
+ " [0., 0., 0., 0.],\n",
759
+ " [0., 0., 0., 0.]])"
760
+ ]
761
+ },
762
+ "execution_count": 53,
763
+ "metadata": {},
764
+ "output_type": "execute_result"
765
+ }
766
+ ],
767
+ "source": [
768
+ "np.empty((3,4))"
769
+ ]
770
+ },
771
+ {
772
+ "cell_type": "code",
773
+ "execution_count": 56,
774
+ "metadata": {},
775
+ "outputs": [
776
+ {
777
+ "data": {
778
+ "text/plain": [
779
+ "array([ 0. , 3.33333333, 6.66666667, 10. ])"
780
+ ]
781
+ },
782
+ "execution_count": 56,
783
+ "metadata": {},
784
+ "output_type": "execute_result"
785
+ }
786
+ ],
787
+ "source": [
788
+ "np.linspace(0,10,4)"
789
+ ]
790
+ },
791
+ {
792
+ "cell_type": "code",
793
+ "execution_count": 57,
794
+ "metadata": {},
795
+ "outputs": [
796
+ {
797
+ "data": {
798
+ "text/plain": [
799
+ "array([0. , 2.5, 5. , 7.5])"
800
+ ]
801
+ },
802
+ "execution_count": 57,
803
+ "metadata": {},
804
+ "output_type": "execute_result"
805
+ }
806
+ ],
807
+ "source": [
808
+ "np.linspace(0,10,4, endpoint=False)"
809
+ ]
810
+ },
811
+ {
812
+ "cell_type": "code",
813
+ "execution_count": 58,
814
+ "metadata": {},
815
+ "outputs": [
816
+ {
817
+ "data": {
818
+ "text/plain": [
819
+ "(array([0. , 2.5, 5. , 7.5]), 2.5)"
820
+ ]
821
+ },
822
+ "execution_count": 58,
823
+ "metadata": {},
824
+ "output_type": "execute_result"
825
+ }
826
+ ],
827
+ "source": [
828
+ "np.linspace(0,10,4, endpoint=False, retstep=True)"
829
+ ]
830
+ },
831
+ {
832
+ "cell_type": "code",
833
+ "execution_count": 59,
834
+ "metadata": {},
835
+ "outputs": [
836
+ {
837
+ "data": {
838
+ "text/plain": [
839
+ "array([[1, 2, 3],\n",
840
+ " [4, 5, 6]])"
841
+ ]
842
+ },
843
+ "execution_count": 59,
844
+ "metadata": {},
845
+ "output_type": "execute_result"
846
+ }
847
+ ],
848
+ "source": [
849
+ "arr = np.array([[1,2,3],[4,5,6]])\n",
850
+ "arr"
851
+ ]
852
+ },
853
+ {
854
+ "cell_type": "code",
855
+ "execution_count": 60,
856
+ "metadata": {},
857
+ "outputs": [
858
+ {
859
+ "data": {
860
+ "text/plain": [
861
+ "array([[0, 0, 0],\n",
862
+ " [0, 0, 0]])"
863
+ ]
864
+ },
865
+ "execution_count": 60,
866
+ "metadata": {},
867
+ "output_type": "execute_result"
868
+ }
869
+ ],
870
+ "source": [
871
+ "np.zeros_like(arr)"
872
+ ]
873
+ },
874
+ {
875
+ "cell_type": "code",
876
+ "execution_count": 61,
877
+ "metadata": {},
878
+ "outputs": [
879
+ {
880
+ "data": {
881
+ "text/plain": [
882
+ "array([[1, 1, 1],\n",
883
+ " [1, 1, 1]])"
884
+ ]
885
+ },
886
+ "execution_count": 61,
887
+ "metadata": {},
888
+ "output_type": "execute_result"
889
+ }
890
+ ],
891
+ "source": [
892
+ "np.ones_like(arr)"
893
+ ]
894
+ },
895
+ {
896
+ "cell_type": "code",
897
+ "execution_count": 62,
898
+ "metadata": {},
899
+ "outputs": [
900
+ {
901
+ "data": {
902
+ "text/plain": [
903
+ "7.38905609893065"
904
+ ]
905
+ },
906
+ "execution_count": 62,
907
+ "metadata": {},
908
+ "output_type": "execute_result"
909
+ }
910
+ ],
911
+ "source": [
912
+ "np.exp(2)"
913
+ ]
914
+ },
915
+ {
916
+ "cell_type": "code",
917
+ "execution_count": null,
918
+ "metadata": {
919
+ "collapsed": true
920
+ },
921
+ "outputs": [],
922
+ "source": []
923
+ }
924
+ ],
925
+ "metadata": {
926
+ "kernelspec": {
927
+ "display_name": "Python 3",
928
+ "language": "python",
929
+ "name": "python3"
930
+ },
931
+ "language_info": {
932
+ "codemirror_mode": {
933
+ "name": "ipython",
934
+ "version": 3
935
+ },
936
+ "file_extension": ".py",
937
+ "mimetype": "text/x-python",
938
+ "name": "python",
939
+ "nbconvert_exporter": "python",
940
+ "pygments_lexer": "ipython3",
941
+ "version": "3.6.3"
942
+ }
943
+ },
944
+ "nbformat": 4,
945
+ "nbformat_minor": 2
946
+ }
python_open_read.ipynb ADDED
@@ -0,0 +1,205 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "w 是以写的方式打开文件 write\n",
8
+ "a 是以追加的方式打开文件 append\n",
9
+ "r 是读的方式打开文件 read"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "execution_count": 4,
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "poem = '\\n让我们一起学习AI python\\n'\n",
19
+ "f = open('./test/poem.txt', 'a')\n",
20
+ "f.write(poem)\n",
21
+ "f.close()"
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "code",
26
+ "execution_count": 5,
27
+ "metadata": {},
28
+ "outputs": [
29
+ {
30
+ "name": "stdout",
31
+ "output_type": "stream",
32
+ "text": [
33
+ "\n",
34
+ "让我们一起学习AI python\n",
35
+ "\n",
36
+ "让我们一起学习AI python\n",
37
+ "\n"
38
+ ]
39
+ }
40
+ ],
41
+ "source": [
42
+ "f = open('./test/poem.txt', 'r')\n",
43
+ "data = f.read()\n",
44
+ "print(data)\n",
45
+ "f.close()"
46
+ ]
47
+ },
48
+ {
49
+ "cell_type": "code",
50
+ "execution_count": 6,
51
+ "metadata": {},
52
+ "outputs": [
53
+ {
54
+ "name": "stdout",
55
+ "output_type": "stream",
56
+ "text": [
57
+ "\n",
58
+ "让我们一起学习AI python\n",
59
+ "\n",
60
+ "让我们一起学习AI python\n",
61
+ "\n"
62
+ ]
63
+ }
64
+ ],
65
+ "source": [
66
+ "with open('./test/poem.txt', 'r') as f:\n",
67
+ " data = f.read()\n",
68
+ " print(data)"
69
+ ]
70
+ },
71
+ {
72
+ "cell_type": "markdown",
73
+ "metadata": {},
74
+ "source": [
75
+ "readline方法每次读出一行内容,所以读取时占用的内存小,比较适合大文件"
76
+ ]
77
+ },
78
+ {
79
+ "cell_type": "code",
80
+ "execution_count": 8,
81
+ "metadata": {},
82
+ "outputs": [
83
+ {
84
+ "name": "stdout",
85
+ "output_type": "stream",
86
+ "text": [
87
+ "\n",
88
+ "\n",
89
+ "让我们一起学习AI python\n",
90
+ "\n",
91
+ "\n",
92
+ "\n",
93
+ "让我们一起学习AI python\n",
94
+ "\n"
95
+ ]
96
+ }
97
+ ],
98
+ "source": [
99
+ "f = open('./test/poem.txt', 'r')\n",
100
+ "line = f.readline()\n",
101
+ "while line:\n",
102
+ " print(line)\n",
103
+ " line = f.readline()\n",
104
+ "f.close()"
105
+ ]
106
+ },
107
+ {
108
+ "cell_type": "markdown",
109
+ "metadata": {},
110
+ "source": [
111
+ "readlines方法读取整个文件所有行,保存在一个列表变量中,每行对于列表的一个元素,但是读取大文件会比较占内存"
112
+ ]
113
+ },
114
+ {
115
+ "cell_type": "code",
116
+ "execution_count": 12,
117
+ "metadata": {
118
+ "scrolled": true
119
+ },
120
+ "outputs": [
121
+ {
122
+ "name": "stdout",
123
+ "output_type": "stream",
124
+ "text": [
125
+ "\n",
126
+ "\n",
127
+ "让我们一起学习AI python\n",
128
+ "\n",
129
+ "\n",
130
+ "\n",
131
+ "让我们一起学习AI python\n",
132
+ "\n"
133
+ ]
134
+ }
135
+ ],
136
+ "source": [
137
+ "f = open('./test/poem.txt', 'r')\n",
138
+ "lines = f.readlines()\n",
139
+ "for line in lines:\n",
140
+ " print(line)\n",
141
+ "f.close()"
142
+ ]
143
+ },
144
+ {
145
+ "cell_type": "code",
146
+ "execution_count": 14,
147
+ "metadata": {
148
+ "collapsed": true
149
+ },
150
+ "outputs": [],
151
+ "source": [
152
+ "poem = '\\n让我们一起学习AI python\\n'\n",
153
+ "f = open('./test/poem.txt', 'w', encoding='utf-8')\n",
154
+ "f.write(poem)\n",
155
+ "f.close()"
156
+ ]
157
+ },
158
+ {
159
+ "cell_type": "code",
160
+ "execution_count": 15,
161
+ "metadata": {},
162
+ "outputs": [
163
+ {
164
+ "name": "stdout",
165
+ "output_type": "stream",
166
+ "text": [
167
+ "\n",
168
+ "\n",
169
+ "让我们一起学习AI python\n",
170
+ "\n"
171
+ ]
172
+ }
173
+ ],
174
+ "source": [
175
+ "f = open('./test/poem.txt', 'r', encoding='utf-8')\n",
176
+ "line = f.readline()\n",
177
+ "while line:\n",
178
+ " print(line)\n",
179
+ " line = f.readline()\n",
180
+ "f.close()"
181
+ ]
182
+ }
183
+ ],
184
+ "metadata": {
185
+ "kernelspec": {
186
+ "display_name": "Python 3",
187
+ "language": "python",
188
+ "name": "python3"
189
+ },
190
+ "language_info": {
191
+ "codemirror_mode": {
192
+ "name": "ipython",
193
+ "version": 3
194
+ },
195
+ "file_extension": ".py",
196
+ "mimetype": "text/x-python",
197
+ "name": "python",
198
+ "nbconvert_exporter": "python",
199
+ "pygments_lexer": "ipython3",
200
+ "version": "3.6.3"
201
+ }
202
+ },
203
+ "nbformat": 4,
204
+ "nbformat_minor": 2
205
+ }
python_os模块.ipynb ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 8,
6
+ "metadata": {
7
+ "collapsed": true
8
+ },
9
+ "outputs": [],
10
+ "source": [
11
+ "import os\n",
12
+ "import shutil"
13
+ ]
14
+ },
15
+ {
16
+ "cell_type": "code",
17
+ "execution_count": 10,
18
+ "metadata": {},
19
+ "outputs": [
20
+ {
21
+ "name": "stdout",
22
+ "output_type": "stream",
23
+ "text": [
24
+ "part-a.txt\n",
25
+ "part-r-0000-a.txt\n",
26
+ "part-b.txt\n",
27
+ "part-r-0000-b.txt\n",
28
+ "part-c.txt\n",
29
+ "part-r-0000-c.txt\n",
30
+ "Done\n"
31
+ ]
32
+ }
33
+ ],
34
+ "source": [
35
+ "d = './test'\n",
36
+ "for file_name in os.listdir(d):\n",
37
+ " print(file_name)\n",
38
+ " new_file_name = file_name.replace('part', 'part-r-0000')\n",
39
+ " print(new_file_name)\n",
40
+ " shutil.move(d+'/'+file_name, d+'/'+new_file_name)\n",
41
+ "print('Done')"
42
+ ]
43
+ }
44
+ ],
45
+ "metadata": {
46
+ "kernelspec": {
47
+ "display_name": "Python 3",
48
+ "language": "python",
49
+ "name": "python3"
50
+ },
51
+ "language_info": {
52
+ "codemirror_mode": {
53
+ "name": "ipython",
54
+ "version": 3
55
+ },
56
+ "file_extension": ".py",
57
+ "mimetype": "text/x-python",
58
+ "name": "python",
59
+ "nbconvert_exporter": "python",
60
+ "pygments_lexer": "ipython3",
61
+ "version": "3.6.3"
62
+ }
63
+ },
64
+ "nbformat": 4,
65
+ "nbformat_minor": 2
66
+ }
python_tuple.ipynb ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 4,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "data": {
10
+ "text/plain": [
11
+ "(tuple, tuple, tuple, tuple)"
12
+ ]
13
+ },
14
+ "execution_count": 4,
15
+ "metadata": {},
16
+ "output_type": "execute_result"
17
+ }
18
+ ],
19
+ "source": [
20
+ "a=1,2,3,4,5,6,7 #创建一个元组 省略了括号\n",
21
+ "b=(1,2,3,4,5,6,7) #创建一个元组\n",
22
+ "c=(42,) #创建一个只有一个元素值的元组\n",
23
+ "d=() #创建一个空的元组\n",
24
+ "type(a), type(b), type(c), type(d)"
25
+ ]
26
+ },
27
+ {
28
+ "cell_type": "code",
29
+ "execution_count": 5,
30
+ "metadata": {},
31
+ "outputs": [
32
+ {
33
+ "data": {
34
+ "text/plain": [
35
+ "2"
36
+ ]
37
+ },
38
+ "execution_count": 5,
39
+ "metadata": {},
40
+ "output_type": "execute_result"
41
+ }
42
+ ],
43
+ "source": [
44
+ "a[1]"
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "execution_count": 6,
50
+ "metadata": {},
51
+ "outputs": [
52
+ {
53
+ "ename": "TypeError",
54
+ "evalue": "'tuple' object does not support item assignment",
55
+ "output_type": "error",
56
+ "traceback": [
57
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
58
+ "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
59
+ "\u001b[1;32m<ipython-input-6-793aca927300>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m20\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
60
+ "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment"
61
+ ]
62
+ }
63
+ ],
64
+ "source": [
65
+ "a[1] = 20"
66
+ ]
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "execution_count": 7,
71
+ "metadata": {},
72
+ "outputs": [
73
+ {
74
+ "ename": "AttributeError",
75
+ "evalue": "'tuple' object has no attribute 'sort'",
76
+ "output_type": "error",
77
+ "traceback": [
78
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
79
+ "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
80
+ "\u001b[1;32m<ipython-input-7-e7eb8b51a6fa>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0ma\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msort\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
81
+ "\u001b[1;31mAttributeError\u001b[0m: 'tuple' object has no attribute 'sort'"
82
+ ]
83
+ }
84
+ ],
85
+ "source": [
86
+ "a.sort()"
87
+ ]
88
+ },
89
+ {
90
+ "cell_type": "code",
91
+ "execution_count": 9,
92
+ "metadata": {},
93
+ "outputs": [
94
+ {
95
+ "data": {
96
+ "text/plain": [
97
+ "[7, 6, 5, 4, 3, 2, 1]"
98
+ ]
99
+ },
100
+ "execution_count": 9,
101
+ "metadata": {},
102
+ "output_type": "execute_result"
103
+ }
104
+ ],
105
+ "source": [
106
+ "sorted(a, reverse=True)"
107
+ ]
108
+ },
109
+ {
110
+ "cell_type": "code",
111
+ "execution_count": 12,
112
+ "metadata": {},
113
+ "outputs": [
114
+ {
115
+ "data": {
116
+ "text/plain": [
117
+ "((10, 40), (20, 50), (30, 60))"
118
+ ]
119
+ },
120
+ "execution_count": 12,
121
+ "metadata": {},
122
+ "output_type": "execute_result"
123
+ }
124
+ ],
125
+ "source": [
126
+ "a = [10,20,30]\n",
127
+ "b = [40,50,60]\n",
128
+ "tuple(zip(a, b))"
129
+ ]
130
+ },
131
+ {
132
+ "cell_type": "code",
133
+ "execution_count": 14,
134
+ "metadata": {},
135
+ "outputs": [
136
+ {
137
+ "data": {
138
+ "text/plain": [
139
+ "[('我', 1), ('你', 2), ('他', 3)]"
140
+ ]
141
+ },
142
+ "execution_count": 14,
143
+ "metadata": {},
144
+ "output_type": "execute_result"
145
+ }
146
+ ],
147
+ "source": [
148
+ "a = [1, 2, 3]\n",
149
+ "b = ['我', '你', '他']\n",
150
+ "list(zip(b,a))"
151
+ ]
152
+ }
153
+ ],
154
+ "metadata": {
155
+ "kernelspec": {
156
+ "display_name": "Python 3",
157
+ "language": "python",
158
+ "name": "python3"
159
+ },
160
+ "language_info": {
161
+ "codemirror_mode": {
162
+ "name": "ipython",
163
+ "version": 3
164
+ },
165
+ "file_extension": ".py",
166
+ "mimetype": "text/x-python",
167
+ "name": "python",
168
+ "nbconvert_exporter": "python",
169
+ "pygments_lexer": "ipython3",
170
+ "version": "3.6.3"
171
+ }
172
+ },
173
+ "nbformat": 4,
174
+ "nbformat_minor": 2
175
+ }
python_切片操作.ipynb ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "data": {
10
+ "text/plain": [
11
+ "'Python'"
12
+ ]
13
+ },
14
+ "execution_count": 1,
15
+ "metadata": {},
16
+ "output_type": "execute_result"
17
+ }
18
+ ],
19
+ "source": [
20
+ "pystr = 'Python'\n",
21
+ "pystr[:]"
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "code",
26
+ "execution_count": 3,
27
+ "metadata": {},
28
+ "outputs": [
29
+ {
30
+ "data": {
31
+ "text/plain": [
32
+ "'thon'"
33
+ ]
34
+ },
35
+ "execution_count": 3,
36
+ "metadata": {},
37
+ "output_type": "execute_result"
38
+ }
39
+ ],
40
+ "source": [
41
+ "pystr[2:]"
42
+ ]
43
+ },
44
+ {
45
+ "cell_type": "code",
46
+ "execution_count": 4,
47
+ "metadata": {},
48
+ "outputs": [
49
+ {
50
+ "data": {
51
+ "text/plain": [
52
+ "'Pytho'"
53
+ ]
54
+ },
55
+ "execution_count": 4,
56
+ "metadata": {},
57
+ "output_type": "execute_result"
58
+ }
59
+ ],
60
+ "source": [
61
+ "pystr[:5]"
62
+ ]
63
+ },
64
+ {
65
+ "cell_type": "code",
66
+ "execution_count": 5,
67
+ "metadata": {},
68
+ "outputs": [
69
+ {
70
+ "data": {
71
+ "text/plain": [
72
+ "'ytho'"
73
+ ]
74
+ },
75
+ "execution_count": 5,
76
+ "metadata": {},
77
+ "output_type": "execute_result"
78
+ }
79
+ ],
80
+ "source": [
81
+ "pystr[1:5]"
82
+ ]
83
+ },
84
+ {
85
+ "cell_type": "code",
86
+ "execution_count": 6,
87
+ "metadata": {},
88
+ "outputs": [
89
+ {
90
+ "data": {
91
+ "text/plain": [
92
+ "'yh'"
93
+ ]
94
+ },
95
+ "execution_count": 6,
96
+ "metadata": {},
97
+ "output_type": "execute_result"
98
+ }
99
+ ],
100
+ "source": [
101
+ "pystr[1:5:2]"
102
+ ]
103
+ },
104
+ {
105
+ "cell_type": "code",
106
+ "execution_count": 7,
107
+ "metadata": {},
108
+ "outputs": [
109
+ {
110
+ "data": {
111
+ "text/plain": [
112
+ "'hon'"
113
+ ]
114
+ },
115
+ "execution_count": 7,
116
+ "metadata": {},
117
+ "output_type": "execute_result"
118
+ }
119
+ ],
120
+ "source": [
121
+ "pystr[-3:]"
122
+ ]
123
+ },
124
+ {
125
+ "cell_type": "code",
126
+ "execution_count": 8,
127
+ "metadata": {},
128
+ "outputs": [
129
+ {
130
+ "data": {
131
+ "text/plain": [
132
+ "'yt'"
133
+ ]
134
+ },
135
+ "execution_count": 8,
136
+ "metadata": {},
137
+ "output_type": "execute_result"
138
+ }
139
+ ],
140
+ "source": [
141
+ "pystr[-5:-3]"
142
+ ]
143
+ },
144
+ {
145
+ "cell_type": "code",
146
+ "execution_count": 11,
147
+ "metadata": {},
148
+ "outputs": [
149
+ {
150
+ "data": {
151
+ "text/plain": [
152
+ "'nhy'"
153
+ ]
154
+ },
155
+ "execution_count": 11,
156
+ "metadata": {},
157
+ "output_type": "execute_result"
158
+ }
159
+ ],
160
+ "source": [
161
+ "pystr[::-2]"
162
+ ]
163
+ },
164
+ {
165
+ "cell_type": "code",
166
+ "execution_count": 12,
167
+ "metadata": {
168
+ "scrolled": true
169
+ },
170
+ "outputs": [
171
+ {
172
+ "data": {
173
+ "text/plain": [
174
+ "'yt'"
175
+ ]
176
+ },
177
+ "execution_count": 12,
178
+ "metadata": {},
179
+ "output_type": "execute_result"
180
+ }
181
+ ],
182
+ "source": [
183
+ "pystr[1:-3]"
184
+ ]
185
+ },
186
+ {
187
+ "cell_type": "code",
188
+ "execution_count": 15,
189
+ "metadata": {},
190
+ "outputs": [
191
+ {
192
+ "data": {
193
+ "text/plain": [
194
+ "15"
195
+ ]
196
+ },
197
+ "execution_count": 15,
198
+ "metadata": {},
199
+ "output_type": "execute_result"
200
+ }
201
+ ],
202
+ "source": [
203
+ "eval(\"5+10\")"
204
+ ]
205
+ },
206
+ {
207
+ "cell_type": "code",
208
+ "execution_count": 16,
209
+ "metadata": {},
210
+ "outputs": [
211
+ {
212
+ "data": {
213
+ "text/plain": [
214
+ "30"
215
+ ]
216
+ },
217
+ "execution_count": 16,
218
+ "metadata": {},
219
+ "output_type": "execute_result"
220
+ }
221
+ ],
222
+ "source": [
223
+ "a = 10\n",
224
+ "b = 20\n",
225
+ "eval(\"a+b\")"
226
+ ]
227
+ }
228
+ ],
229
+ "metadata": {
230
+ "kernelspec": {
231
+ "display_name": "Python 3",
232
+ "language": "python",
233
+ "name": "python3"
234
+ },
235
+ "language_info": {
236
+ "codemirror_mode": {
237
+ "name": "ipython",
238
+ "version": 3
239
+ },
240
+ "file_extension": ".py",
241
+ "mimetype": "text/x-python",
242
+ "name": "python",
243
+ "nbconvert_exporter": "python",
244
+ "pygments_lexer": "ipython3",
245
+ "version": "3.6.3"
246
+ }
247
+ },
248
+ "nbformat": 4,
249
+ "nbformat_minor": 2
250
+ }
result.jpg ADDED
test/part-r-0000-a.txt ADDED
File without changes
test/part-r-0000-b.txt ADDED
File without changes
test/part-r-0000-c.txt ADDED
File without changes
test/poem.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+
2
+ 让我们一起学习AI python
人工智能-第1阶段Python基础.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:dc4738dffefa5dcd88b2a5a43ad09eb27333280795e47e70a44bf45dac942967
3
+ size 9829331
人工智能-第1阶段python进阶和高级编程.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e36d13b992a3d81b3ff3e9bedd6645b7ff4089795fe62868f18e3a4d178ffc30
3
+ size 7885319
类的定义.ipynb ADDED
@@ -0,0 +1,275 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 77,
6
+ "metadata": {},
7
+ "outputs": [],
8
+ "source": [
9
+ "class Student(object):\n",
10
+ " #company = \"尚学堂\"\n",
11
+ " __company = \"百战尚学堂\"\n",
12
+ " count = 0\n",
13
+ " \n",
14
+ " def __init__(self, temp_name, temp_age):\n",
15
+ " self.name = temp_name\n",
16
+ " self.age = temp_age\n",
17
+ " Student.count += 1\n",
18
+ " \n",
19
+ " def change_age(self, new_age):\n",
20
+ " self.age = new_age\n",
21
+ " \n",
22
+ " def get_name(self):\n",
23
+ " return self.name\n",
24
+ " \n",
25
+ " def __str__(self):\n",
26
+ " return \"student name is %s, student age is %s\" % (self.name, self.age)\n",
27
+ " \n",
28
+ " def __call__(self, a):\n",
29
+ " if self.age + a > 18: \n",
30
+ " return True \n",
31
+ " else: \n",
32
+ " return False\n",
33
+ " \n",
34
+ " def __add__(self, other):\n",
35
+ " return self.age + other.age"
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "code",
40
+ "execution_count": 74,
41
+ "metadata": {},
42
+ "outputs": [
43
+ {
44
+ "ename": "AttributeError",
45
+ "evalue": "type object 'Student' has no attribute '__company'",
46
+ "output_type": "error",
47
+ "traceback": [
48
+ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
49
+ "\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
50
+ "\u001b[1;32m<ipython-input-74-192fdfd33a17>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mStudent\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__company\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
51
+ "\u001b[1;31mAttributeError\u001b[0m: type object 'Student' has no attribute '__company'"
52
+ ]
53
+ }
54
+ ],
55
+ "source": [
56
+ "Student.__company"
57
+ ]
58
+ },
59
+ {
60
+ "cell_type": "code",
61
+ "execution_count": 78,
62
+ "metadata": {},
63
+ "outputs": [],
64
+ "source": [
65
+ "s1 = Student(\"张三\", 18)"
66
+ ]
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "execution_count": 34,
71
+ "metadata": {},
72
+ "outputs": [
73
+ {
74
+ "name": "stdout",
75
+ "output_type": "stream",
76
+ "text": [
77
+ "张三\n",
78
+ "18\n",
79
+ "张三\n"
80
+ ]
81
+ }
82
+ ],
83
+ "source": [
84
+ "print(s1.name)\n",
85
+ "print(s1.age)\n",
86
+ "print(s1.get_name())"
87
+ ]
88
+ },
89
+ {
90
+ "cell_type": "code",
91
+ "execution_count": 35,
92
+ "metadata": {},
93
+ "outputs": [
94
+ {
95
+ "name": "stdout",
96
+ "output_type": "stream",
97
+ "text": [
98
+ "20\n"
99
+ ]
100
+ }
101
+ ],
102
+ "source": [
103
+ "s1.change_age(20)\n",
104
+ "print(s1.age)"
105
+ ]
106
+ },
107
+ {
108
+ "cell_type": "code",
109
+ "execution_count": 36,
110
+ "metadata": {},
111
+ "outputs": [
112
+ {
113
+ "name": "stdout",
114
+ "output_type": "stream",
115
+ "text": [
116
+ "尚学堂\n",
117
+ "1\n"
118
+ ]
119
+ }
120
+ ],
121
+ "source": [
122
+ "print(Student.company)\n",
123
+ "print(Student.count)"
124
+ ]
125
+ },
126
+ {
127
+ "cell_type": "code",
128
+ "execution_count": 79,
129
+ "metadata": {
130
+ "collapsed": true
131
+ },
132
+ "outputs": [],
133
+ "source": [
134
+ "s2 = Student(\"李四\", 19)"
135
+ ]
136
+ },
137
+ {
138
+ "cell_type": "code",
139
+ "execution_count": 38,
140
+ "metadata": {},
141
+ "outputs": [
142
+ {
143
+ "name": "stdout",
144
+ "output_type": "stream",
145
+ "text": [
146
+ "尚学堂\n",
147
+ "2\n"
148
+ ]
149
+ }
150
+ ],
151
+ "source": [
152
+ "print(Student.company)\n",
153
+ "print(Student.count)"
154
+ ]
155
+ },
156
+ {
157
+ "cell_type": "code",
158
+ "execution_count": 42,
159
+ "metadata": {},
160
+ "outputs": [
161
+ {
162
+ "name": "stdout",
163
+ "output_type": "stream",
164
+ "text": [
165
+ "student name is 李四, student age is 19\n"
166
+ ]
167
+ }
168
+ ],
169
+ "source": [
170
+ "print(s2)"
171
+ ]
172
+ },
173
+ {
174
+ "cell_type": "code",
175
+ "execution_count": 59,
176
+ "metadata": {},
177
+ "outputs": [
178
+ {
179
+ "data": {
180
+ "text/plain": [
181
+ "(True, True)"
182
+ ]
183
+ },
184
+ "execution_count": 59,
185
+ "metadata": {},
186
+ "output_type": "execute_result"
187
+ }
188
+ ],
189
+ "source": [
190
+ "s1(1), s2(1)"
191
+ ]
192
+ },
193
+ {
194
+ "cell_type": "code",
195
+ "execution_count": 67,
196
+ "metadata": {},
197
+ "outputs": [
198
+ {
199
+ "data": {
200
+ "text/plain": [
201
+ "37"
202
+ ]
203
+ },
204
+ "execution_count": 67,
205
+ "metadata": {},
206
+ "output_type": "execute_result"
207
+ }
208
+ ],
209
+ "source": [
210
+ "s2 + s1"
211
+ ]
212
+ },
213
+ {
214
+ "cell_type": "code",
215
+ "execution_count": 80,
216
+ "metadata": {},
217
+ "outputs": [
218
+ {
219
+ "data": {
220
+ "text/plain": [
221
+ "__main__.Student"
222
+ ]
223
+ },
224
+ "execution_count": 80,
225
+ "metadata": {},
226
+ "output_type": "execute_result"
227
+ }
228
+ ],
229
+ "source": [
230
+ "type(s1)"
231
+ ]
232
+ },
233
+ {
234
+ "cell_type": "code",
235
+ "execution_count": 81,
236
+ "metadata": {},
237
+ "outputs": [
238
+ {
239
+ "data": {
240
+ "text/plain": [
241
+ "True"
242
+ ]
243
+ },
244
+ "execution_count": 81,
245
+ "metadata": {},
246
+ "output_type": "execute_result"
247
+ }
248
+ ],
249
+ "source": [
250
+ "isinstance(s1, Student)"
251
+ ]
252
+ }
253
+ ],
254
+ "metadata": {
255
+ "kernelspec": {
256
+ "display_name": "Python 3",
257
+ "language": "python",
258
+ "name": "python3"
259
+ },
260
+ "language_info": {
261
+ "codemirror_mode": {
262
+ "name": "ipython",
263
+ "version": 3
264
+ },
265
+ "file_extension": ".py",
266
+ "mimetype": "text/x-python",
267
+ "name": "python",
268
+ "nbconvert_exporter": "python",
269
+ "pygments_lexer": "ipython3",
270
+ "version": "3.6.3"
271
+ }
272
+ },
273
+ "nbformat": 4,
274
+ "nbformat_minor": 2
275
+ }
类的继承.ipynb ADDED
@@ -0,0 +1,148 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 7,
6
+ "metadata": {
7
+ "collapsed": true
8
+ },
9
+ "outputs": [],
10
+ "source": [
11
+ "class Person: \n",
12
+ " def sing(self):\n",
13
+ " print(\"人在唱歌\")\n",
14
+ " \n",
15
+ "class Student(Person):\n",
16
+ " def dance(self):\n",
17
+ " print(\"人在跳舞\")\n",
18
+ " \n",
19
+ "class Teacher(Person):\n",
20
+ " pass"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": 8,
26
+ "metadata": {},
27
+ "outputs": [
28
+ {
29
+ "name": "stdout",
30
+ "output_type": "stream",
31
+ "text": [
32
+ "人在跳舞\n",
33
+ "人在唱歌\n",
34
+ "人在唱歌\n"
35
+ ]
36
+ }
37
+ ],
38
+ "source": [
39
+ "s1 = Student()\n",
40
+ "s1.dance()\n",
41
+ "s1.sing()\n",
42
+ "\n",
43
+ "t1 = Teacher()\n",
44
+ "t1.sing()"
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "execution_count": 21,
50
+ "metadata": {
51
+ "collapsed": true
52
+ },
53
+ "outputs": [],
54
+ "source": [
55
+ "class Person: \n",
56
+ " def __init__(self,name,age):\n",
57
+ " self.name = name\n",
58
+ " self.age = age\n",
59
+ " \n",
60
+ " def sing(self):\n",
61
+ " print(\"人在唱歌\")\n",
62
+ " \n",
63
+ "class Student(Person):\n",
64
+ " def __init__(self,name,age,score):\n",
65
+ " self.score = score\n",
66
+ " Person.__init__(self, name, age)\n",
67
+ " \n",
68
+ " def dance(self):\n",
69
+ " print(\"人在跳舞\")\n",
70
+ " \n",
71
+ " def sing(self, song):\n",
72
+ " super().sing()\n",
73
+ " print(\"在唱%s\"%song)\n",
74
+ " \n",
75
+ "class Teacher(Person):\n",
76
+ " pass"
77
+ ]
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "execution_count": 22,
82
+ "metadata": {},
83
+ "outputs": [],
84
+ "source": [
85
+ "s1 = Student(\"张三\", 18, 100)"
86
+ ]
87
+ },
88
+ {
89
+ "cell_type": "code",
90
+ "execution_count": 23,
91
+ "metadata": {},
92
+ "outputs": [
93
+ {
94
+ "data": {
95
+ "text/plain": [
96
+ "('张三', 18, 100)"
97
+ ]
98
+ },
99
+ "execution_count": 23,
100
+ "metadata": {},
101
+ "output_type": "execute_result"
102
+ }
103
+ ],
104
+ "source": [
105
+ "s1.name, s1.age, s1.score"
106
+ ]
107
+ },
108
+ {
109
+ "cell_type": "code",
110
+ "execution_count": 24,
111
+ "metadata": {},
112
+ "outputs": [
113
+ {
114
+ "name": "stdout",
115
+ "output_type": "stream",
116
+ "text": [
117
+ "人在唱歌\n",
118
+ "在唱黄河大合唱\n"
119
+ ]
120
+ }
121
+ ],
122
+ "source": [
123
+ "s1.sing(\"黄河大合唱\")"
124
+ ]
125
+ }
126
+ ],
127
+ "metadata": {
128
+ "kernelspec": {
129
+ "display_name": "Python 3",
130
+ "language": "python",
131
+ "name": "python3"
132
+ },
133
+ "language_info": {
134
+ "codemirror_mode": {
135
+ "name": "ipython",
136
+ "version": 3
137
+ },
138
+ "file_extension": ".py",
139
+ "mimetype": "text/x-python",
140
+ "name": "python",
141
+ "nbconvert_exporter": "python",
142
+ "pygments_lexer": "ipython3",
143
+ "version": "3.6.3"
144
+ }
145
+ },
146
+ "nbformat": 4,
147
+ "nbformat_minor": 2
148
+ }
闭包和装饰器.ipynb ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "name": "stdout",
10
+ "output_type": "stream",
11
+ "text": [
12
+ "结果: 30\n"
13
+ ]
14
+ }
15
+ ],
16
+ "source": [
17
+ "def func_out(num1):\n",
18
+ " def func_in(num2):\n",
19
+ " return num1+num2\n",
20
+ " return func_in\n",
21
+ "f=func_out(10)\n",
22
+ "result=f(20)\n",
23
+ "print('结果:',result)"
24
+ ]
25
+ },
26
+ {
27
+ "cell_type": "code",
28
+ "execution_count": 8,
29
+ "metadata": {},
30
+ "outputs": [],
31
+ "source": [
32
+ "def log(func):\n",
33
+ " def wrapper(a, b):\n",
34
+ " func(\"%s和%s相约鹊桥\"%(a,b))\n",
35
+ " func(\"%s和%s看电影\"%(a,b))\n",
36
+ " func(\"%s和%s明年见\"%(a,b))\n",
37
+ " return wrapper"
38
+ ]
39
+ },
40
+ {
41
+ "cell_type": "code",
42
+ "execution_count": 10,
43
+ "metadata": {},
44
+ "outputs": [
45
+ {
46
+ "name": "stdout",
47
+ "output_type": "stream",
48
+ "text": [
49
+ "牛郎和织女相约鹊桥\n",
50
+ "牛郎和织女看点电影\n",
51
+ "牛郎和织女明年见\n"
52
+ ]
53
+ }
54
+ ],
55
+ "source": [
56
+ "log(print)(\"牛郎\", \"织女\")"
57
+ ]
58
+ },
59
+ {
60
+ "cell_type": "markdown",
61
+ "metadata": {},
62
+ "source": [
63
+ "装饰器 decorator"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": 21,
69
+ "metadata": {
70
+ "collapsed": true
71
+ },
72
+ "outputs": [],
73
+ "source": [
74
+ "def log(func):\n",
75
+ " def wrapper():\n",
76
+ " print(\"约会开始了\")\n",
77
+ " func()\n",
78
+ " print(\"明年见\")\n",
79
+ " return wrapper"
80
+ ]
81
+ },
82
+ {
83
+ "cell_type": "code",
84
+ "execution_count": 30,
85
+ "metadata": {},
86
+ "outputs": [],
87
+ "source": [
88
+ "@log\n",
89
+ "def my_deca():\n",
90
+ " print(\"牛郎和织女看电影\")"
91
+ ]
92
+ },
93
+ {
94
+ "cell_type": "code",
95
+ "execution_count": 31,
96
+ "metadata": {},
97
+ "outputs": [
98
+ {
99
+ "name": "stdout",
100
+ "output_type": "stream",
101
+ "text": [
102
+ "约会开始了\n",
103
+ "牛郎和织女看电影\n",
104
+ "明年见\n"
105
+ ]
106
+ }
107
+ ],
108
+ "source": [
109
+ "my_deca()"
110
+ ]
111
+ }
112
+ ],
113
+ "metadata": {
114
+ "kernelspec": {
115
+ "display_name": "Python 3",
116
+ "language": "python",
117
+ "name": "python3"
118
+ },
119
+ "language_info": {
120
+ "codemirror_mode": {
121
+ "name": "ipython",
122
+ "version": 3
123
+ },
124
+ "file_extension": ".py",
125
+ "mimetype": "text/x-python",
126
+ "name": "python",
127
+ "nbconvert_exporter": "python",
128
+ "pygments_lexer": "ipython3",
129
+ "version": "3.6.3"
130
+ }
131
+ },
132
+ "nbformat": 4,
133
+ "nbformat_minor": 2
134
+ }