1
+ {
2
+ "nbformat" : 4 ,
3
+ "nbformat_minor" : 0 ,
4
+ "metadata" : {
5
+ "colab" : {
6
+ "provenance" : [],
7
+ "authorship_tag" : " ABX9TyOlIRrk1QL/sCds30j6r5zo" ,
8
+ "include_colab_link" : true
9
+ },
10
+ "kernelspec" : {
11
+ "name" : " python3" ,
12
+ "display_name" : " Python 3"
13
+ },
14
+ "language_info" : {
15
+ "name" : " python"
16
+ }
17
+ },
18
+ "cells" : [
19
+ {
20
+ "cell_type" : " markdown" ,
21
+ "metadata" : {
22
+ "id" : " view-in-github" ,
23
+ "colab_type" : " text"
24
+ },
25
+ "source" : [
26
+ " <a href=\" https://colab.research.google.com/github/Sinrez/PythonProjects/blob/main/hw1_pandas_in_act.ipynb\" target=\" _parent\" ><img src=\" https://colab.research.google.com/assets/colab-badge.svg\" alt=\" Open In Colab\" /></a>"
27
+ ]
28
+ },
29
+ {
30
+ "cell_type" : " code" ,
31
+ "execution_count" : 1 ,
32
+ "metadata" : {
33
+ "id" : " kSISR-dXGfY1"
34
+ },
35
+ "outputs" : [],
36
+ "source" : [
37
+ " import pandas as pd\n " ,
38
+ " \n " ,
39
+ " superheroes = [\n " ,
40
+ " \" Batman\" ,\n " ,
41
+ " \" Superman\" ,\n " ,
42
+ " \" Spider-Man\" ,\n " ,
43
+ " \" Iron Man\" ,\n " ,
44
+ " \" Captain America\" ,\n " ,
45
+ " \" Wonder Woman\"\n " ,
46
+ " ]\n " ,
47
+ " \n " ,
48
+ " strength_levels = (100, 120, 90, 95, 110, 120)"
49
+ ]
50
+ },
51
+ {
52
+ "cell_type" : " code" ,
53
+ "source" : [
54
+ " # Заполните новый объект Series значениями из списка супергероев\n " ,
55
+ " hers = pd.Series(superheroes)\n " ,
56
+ " hers"
57
+ ],
58
+ "metadata" : {
59
+ "colab" : {
60
+ "base_uri" : " https://localhost:8080/"
61
+ },
62
+ "id" : " EWGHmFglHGLZ" ,
63
+ "outputId" : " 1bf3760b-f50c-43fb-d297-d4eaf8c6b51b"
64
+ },
65
+ "execution_count" : 2 ,
66
+ "outputs" : [
67
+ {
68
+ "output_type" : " execute_result" ,
69
+ "data" : {
70
+ "text/plain" : [
71
+ " 0 Batman\n " ,
72
+ " 1 Superman\n " ,
73
+ " 2 Spider-Man\n " ,
74
+ " 3 Iron Man\n " ,
75
+ " 4 Captain America\n " ,
76
+ " 5 Wonder Woman\n " ,
77
+ " dtype: object"
78
+ ]
79
+ },
80
+ "metadata" : {},
81
+ "execution_count" : 2
82
+ }
83
+ ]
84
+ },
85
+ {
86
+ "cell_type" : " code" ,
87
+ "source" : [
88
+ " # Заполните новый объект Series значениями из кортежа уровней силы\n " ,
89
+ " hers = pd.Series(index = superheroes, data=strength_levels)\n " ,
90
+ " hers"
91
+ ],
92
+ "metadata" : {
93
+ "colab" : {
94
+ "base_uri" : " https://localhost:8080/"
95
+ },
96
+ "id" : " nJW6WVj5HQc0" ,
97
+ "outputId" : " 2f92ce5a-6ea0-464a-8cf8-9a95c0cda36a"
98
+ },
99
+ "execution_count" : 10 ,
100
+ "outputs" : [
101
+ {
102
+ "output_type" : " execute_result" ,
103
+ "data" : {
104
+ "text/plain" : [
105
+ " Batman 100\n " ,
106
+ " Superman 120\n " ,
107
+ " Spider-Man 90\n " ,
108
+ " Iron Man 95\n " ,
109
+ " Captain America 110\n " ,
110
+ " Wonder Woman 120\n " ,
111
+ " dtype: int64"
112
+ ]
113
+ },
114
+ "metadata" : {},
115
+ "execution_count" : 10
116
+ }
117
+ ]
118
+ },
119
+ {
120
+ "cell_type" : " code" ,
121
+ "source" : [
122
+ " # Извлеките первые две строки из объекта Series heroes\n " ,
123
+ " hers.head(2)"
124
+ ],
125
+ "metadata" : {
126
+ "colab" : {
127
+ "base_uri" : " https://localhost:8080/"
128
+ },
129
+ "id" : " jN6FTB4dHZvy" ,
130
+ "outputId" : " f92573d3-f563-4d5b-979b-7e2eeafd6f8d"
131
+ },
132
+ "execution_count" : 5 ,
133
+ "outputs" : [
134
+ {
135
+ "output_type" : " execute_result" ,
136
+ "data" : {
137
+ "text/plain" : [
138
+ " 100 Batman\n " ,
139
+ " 120 Superman\n " ,
140
+ " dtype: object"
141
+ ]
142
+ },
143
+ "metadata" : {},
144
+ "execution_count" : 5
145
+ }
146
+ ]
147
+ },
148
+ {
149
+ "cell_type" : " code" ,
150
+ "source" : [
151
+ " # Извлеките последние четыре строки из объекта Series heroes\n " ,
152
+ " hers.tail(4)"
153
+ ],
154
+ "metadata" : {
155
+ "colab" : {
156
+ "base_uri" : " https://localhost:8080/"
157
+ },
158
+ "id" : " stovSMXfJfgh" ,
159
+ "outputId" : " 4f542740-f12d-42b5-b78e-f712d6209226"
160
+ },
161
+ "execution_count" : 6 ,
162
+ "outputs" : [
163
+ {
164
+ "output_type" : " execute_result" ,
165
+ "data" : {
166
+ "text/plain" : [
167
+ " 90 Spider-Man\n " ,
168
+ " 95 Iron Man\n " ,
169
+ " 110 Captain America\n " ,
170
+ " 120 Wonder Woman\n " ,
171
+ " dtype: object"
172
+ ]
173
+ },
174
+ "metadata" : {},
175
+ "execution_count" : 6
176
+ }
177
+ ]
178
+ },
179
+ {
180
+ "cell_type" : " code" ,
181
+ "source" : [
182
+ " # Определите количество уникальных значений в heroes\n " ,
183
+ " hers.nunique()"
184
+ ],
185
+ "metadata" : {
186
+ "colab" : {
187
+ "base_uri" : " https://localhost:8080/"
188
+ },
189
+ "id" : " HXKSHFZTJlHa" ,
190
+ "outputId" : " f69135fd-a7cf-411e-8ec3-18f575aa8ce8"
191
+ },
192
+ "execution_count" : 9 ,
193
+ "outputs" : [
194
+ {
195
+ "output_type" : " execute_result" ,
196
+ "data" : {
197
+ "text/plain" : [
198
+ " 6"
199
+ ]
200
+ },
201
+ "metadata" : {},
202
+ "execution_count" : 9
203
+ }
204
+ ]
205
+ },
206
+ {
207
+ "cell_type" : " code" ,
208
+ "source" : [
209
+ " # Вычислите среднюю силу супергероев в heroes\n " ,
210
+ " hers.mean()"
211
+ ],
212
+ "metadata" : {
213
+ "colab" : {
214
+ "base_uri" : " https://localhost:8080/"
215
+ },
216
+ "id" : " NfcjNQtUJtBe" ,
217
+ "outputId" : " a050b963-7c2c-4c1c-e6bd-86362e84ede4"
218
+ },
219
+ "execution_count" : 12 ,
220
+ "outputs" : [
221
+ {
222
+ "output_type" : " execute_result" ,
223
+ "data" : {
224
+ "text/plain" : [
225
+ " 105.83333333333333"
226
+ ]
227
+ },
228
+ "metadata" : {},
229
+ "execution_count" : 12
230
+ }
231
+ ]
232
+ },
233
+ {
234
+ "cell_type" : " code" ,
235
+ "source" : [
236
+ " # Вычислите максимальную и минимальную силу в heroes\n " ,
237
+ " print(hers.max())\n " ,
238
+ " print(hers.min())"
239
+ ],
240
+ "metadata" : {
241
+ "colab" : {
242
+ "base_uri" : " https://localhost:8080/"
243
+ },
244
+ "id" : " bS8gjAa_J-Q2" ,
245
+ "outputId" : " 4377b924-3c4f-424a-b9a8-244342026286"
246
+ },
247
+ "execution_count" : 13 ,
248
+ "outputs" : [
249
+ {
250
+ "output_type" : " stream" ,
251
+ "name" : " stdout" ,
252
+ "text" : [
253
+ " 120\n " ,
254
+ " 90\n "
255
+ ]
256
+ }
257
+ ]
258
+ },
259
+ {
260
+ "cell_type" : " code" ,
261
+ "source" : [
262
+ " # Вычислите, каким будет уровень силы каждого из супергероев при удвоении\n " ,
263
+ " hers_n = hers * 2\n " ,
264
+ " hers_n"
265
+ ],
266
+ "metadata" : {
267
+ "colab" : {
268
+ "base_uri" : " https://localhost:8080/"
269
+ },
270
+ "id" : " AJH4tZLeKFAP" ,
271
+ "outputId" : " a8b7c9d3-dfa6-4ecb-8130-ad77a7b2d0a4"
272
+ },
273
+ "execution_count" : 15 ,
274
+ "outputs" : [
275
+ {
276
+ "output_type" : " execute_result" ,
277
+ "data" : {
278
+ "text/plain" : [
279
+ " Batman 200\n " ,
280
+ " Superman 240\n " ,
281
+ " Spider-Man 180\n " ,
282
+ " Iron Man 190\n " ,
283
+ " Captain America 220\n " ,
284
+ " Wonder Woman 240\n " ,
285
+ " dtype: int64"
286
+ ]
287
+ },
288
+ "metadata" : {},
289
+ "execution_count" : 15
290
+ }
291
+ ]
292
+ },
293
+ {
294
+ "cell_type" : " code" ,
295
+ "source" : [
296
+ " # Преобразуйте объект Series heroes в ассоциативный массив языка Pythonhe\n " ,
297
+ " hers_dict = dict(hers)\n " ,
298
+ " hers_dict"
299
+ ],
300
+ "metadata" : {
301
+ "colab" : {
302
+ "base_uri" : " https://localhost:8080/"
303
+ },
304
+ "id" : " _j4ucCGvKPrU" ,
305
+ "outputId" : " 87812bea-25cd-4f58-cdab-7b9270af571d"
306
+ },
307
+ "execution_count" : 16 ,
308
+ "outputs" : [
309
+ {
310
+ "output_type" : " execute_result" ,
311
+ "data" : {
312
+ "text/plain" : [
313
+ " {'Batman': 100,\n " ,
314
+ " 'Superman': 120,\n " ,
315
+ " 'Spider-Man': 90,\n " ,
316
+ " 'Iron Man': 95,\n " ,
317
+ " 'Captain America': 110,\n " ,
318
+ " 'Wonder Woman': 120}"
319
+ ]
320
+ },
321
+ "metadata" : {},
322
+ "execution_count" : 16
323
+ }
324
+ ]
325
+ }
326
+ ]
327
+ }
0 commit comments