myawesomepkg 0.1.5__py3-none-any.whl → 0.1.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1013 @@
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "1fd1dba2",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import numpy as np\n",
11
+ "import pandas as pd\n"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": 2,
17
+ "id": "2b7ac399",
18
+ "metadata": {},
19
+ "outputs": [
20
+ {
21
+ "data": {
22
+ "text/plain": [
23
+ "array([1, None, 3, 4], dtype=object)"
24
+ ]
25
+ },
26
+ "execution_count": 2,
27
+ "metadata": {},
28
+ "output_type": "execute_result"
29
+ }
30
+ ],
31
+ "source": [
32
+ "vals1 = np.array([1, None, 3, 4])\n",
33
+ "vals1"
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "execution_count": 4,
39
+ "id": "50393a54",
40
+ "metadata": {},
41
+ "outputs": [
42
+ {
43
+ "name": "stdout",
44
+ "output_type": "stream",
45
+ "text": [
46
+ "dtype = object\n",
47
+ "63.4 ms ± 4.21 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)\n",
48
+ "\n",
49
+ "dtype = int\n",
50
+ "2.24 ms ± 134 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)\n",
51
+ "\n"
52
+ ]
53
+ }
54
+ ],
55
+ "source": [
56
+ "for dtype in ['object', 'int']:\n",
57
+ " print(\"dtype =\", dtype)\n",
58
+ " %timeit np.arange(1E6, dtype=dtype).sum()\n",
59
+ " print()"
60
+ ]
61
+ },
62
+ {
63
+ "cell_type": "code",
64
+ "execution_count": 6,
65
+ "id": "ef13ae07",
66
+ "metadata": {},
67
+ "outputs": [
68
+ {
69
+ "data": {
70
+ "text/plain": [
71
+ "dtype('float64')"
72
+ ]
73
+ },
74
+ "execution_count": 6,
75
+ "metadata": {},
76
+ "output_type": "execute_result"
77
+ }
78
+ ],
79
+ "source": [
80
+ "vals2 = np.array([1, np.nan, 3, 4])\n",
81
+ "vals2.dtype\n",
82
+ "\n"
83
+ ]
84
+ },
85
+ {
86
+ "cell_type": "code",
87
+ "execution_count": 7,
88
+ "id": "a608bfd2",
89
+ "metadata": {},
90
+ "outputs": [
91
+ {
92
+ "data": {
93
+ "text/plain": [
94
+ "nan"
95
+ ]
96
+ },
97
+ "execution_count": 7,
98
+ "metadata": {},
99
+ "output_type": "execute_result"
100
+ }
101
+ ],
102
+ "source": [
103
+ "1 + np.nan"
104
+ ]
105
+ },
106
+ {
107
+ "cell_type": "code",
108
+ "execution_count": 8,
109
+ "id": "ee1ea156",
110
+ "metadata": {},
111
+ "outputs": [
112
+ {
113
+ "data": {
114
+ "text/plain": [
115
+ "nan"
116
+ ]
117
+ },
118
+ "execution_count": 8,
119
+ "metadata": {},
120
+ "output_type": "execute_result"
121
+ }
122
+ ],
123
+ "source": [
124
+ "0 * np.nan"
125
+ ]
126
+ },
127
+ {
128
+ "cell_type": "code",
129
+ "execution_count": 9,
130
+ "id": "710ab0fa",
131
+ "metadata": {},
132
+ "outputs": [
133
+ {
134
+ "data": {
135
+ "text/plain": [
136
+ "(nan, nan, nan)"
137
+ ]
138
+ },
139
+ "execution_count": 9,
140
+ "metadata": {},
141
+ "output_type": "execute_result"
142
+ }
143
+ ],
144
+ "source": [
145
+ "vals2.sum(), vals2.min(), vals2.max()\n"
146
+ ]
147
+ },
148
+ {
149
+ "cell_type": "code",
150
+ "execution_count": 10,
151
+ "id": "57cd4e3a",
152
+ "metadata": {},
153
+ "outputs": [
154
+ {
155
+ "data": {
156
+ "text/plain": [
157
+ "(8.0, 1.0, 4.0)"
158
+ ]
159
+ },
160
+ "execution_count": 10,
161
+ "metadata": {},
162
+ "output_type": "execute_result"
163
+ }
164
+ ],
165
+ "source": [
166
+ "np.nansum(vals2), np.nanmin(vals2), np.nanmax(vals2)\n"
167
+ ]
168
+ },
169
+ {
170
+ "cell_type": "code",
171
+ "execution_count": 12,
172
+ "id": "648ccea3",
173
+ "metadata": {},
174
+ "outputs": [
175
+ {
176
+ "data": {
177
+ "text/plain": [
178
+ "0 1.0\n",
179
+ "1 NaN\n",
180
+ "2 2.0\n",
181
+ "3 NaN\n",
182
+ "dtype: float64"
183
+ ]
184
+ },
185
+ "execution_count": 12,
186
+ "metadata": {},
187
+ "output_type": "execute_result"
188
+ }
189
+ ],
190
+ "source": [
191
+ "pd.Series([1, np.nan, 2, None])\n"
192
+ ]
193
+ },
194
+ {
195
+ "cell_type": "code",
196
+ "execution_count": 13,
197
+ "id": "8ecef540",
198
+ "metadata": {},
199
+ "outputs": [
200
+ {
201
+ "data": {
202
+ "text/plain": [
203
+ "0 0\n",
204
+ "1 1\n",
205
+ "dtype: int32"
206
+ ]
207
+ },
208
+ "execution_count": 13,
209
+ "metadata": {},
210
+ "output_type": "execute_result"
211
+ }
212
+ ],
213
+ "source": [
214
+ "x = pd.Series(range(2), dtype=int)\n",
215
+ "x"
216
+ ]
217
+ },
218
+ {
219
+ "cell_type": "code",
220
+ "execution_count": 14,
221
+ "id": "097233c1",
222
+ "metadata": {},
223
+ "outputs": [
224
+ {
225
+ "data": {
226
+ "text/plain": [
227
+ "0 NaN\n",
228
+ "1 1.0\n",
229
+ "dtype: float64"
230
+ ]
231
+ },
232
+ "execution_count": 14,
233
+ "metadata": {},
234
+ "output_type": "execute_result"
235
+ }
236
+ ],
237
+ "source": [
238
+ "x[0] = None\n",
239
+ "x"
240
+ ]
241
+ },
242
+ {
243
+ "cell_type": "code",
244
+ "execution_count": 15,
245
+ "id": "f2b81620",
246
+ "metadata": {},
247
+ "outputs": [],
248
+ "source": [
249
+ "#Detecting null values\n",
250
+ "data = pd.Series([1, np.nan, 'hello', None])\n"
251
+ ]
252
+ },
253
+ {
254
+ "cell_type": "code",
255
+ "execution_count": 16,
256
+ "id": "11a5c988",
257
+ "metadata": {},
258
+ "outputs": [
259
+ {
260
+ "data": {
261
+ "text/plain": [
262
+ "0 False\n",
263
+ "1 True\n",
264
+ "2 False\n",
265
+ "3 True\n",
266
+ "dtype: bool"
267
+ ]
268
+ },
269
+ "execution_count": 16,
270
+ "metadata": {},
271
+ "output_type": "execute_result"
272
+ }
273
+ ],
274
+ "source": [
275
+ "data.isnull()\n"
276
+ ]
277
+ },
278
+ {
279
+ "cell_type": "code",
280
+ "execution_count": 17,
281
+ "id": "9ecaa9a5",
282
+ "metadata": {},
283
+ "outputs": [
284
+ {
285
+ "data": {
286
+ "text/plain": [
287
+ "0 1\n",
288
+ "2 hello\n",
289
+ "dtype: object"
290
+ ]
291
+ },
292
+ "execution_count": 17,
293
+ "metadata": {},
294
+ "output_type": "execute_result"
295
+ }
296
+ ],
297
+ "source": [
298
+ "data[data.notnull()]\n"
299
+ ]
300
+ },
301
+ {
302
+ "cell_type": "code",
303
+ "execution_count": 18,
304
+ "id": "d7c214eb",
305
+ "metadata": {},
306
+ "outputs": [
307
+ {
308
+ "data": {
309
+ "text/plain": [
310
+ "0 1\n",
311
+ "2 hello\n",
312
+ "dtype: object"
313
+ ]
314
+ },
315
+ "execution_count": 18,
316
+ "metadata": {},
317
+ "output_type": "execute_result"
318
+ }
319
+ ],
320
+ "source": [
321
+ "#Dropping null values\n",
322
+ "data.dropna()\n"
323
+ ]
324
+ },
325
+ {
326
+ "cell_type": "code",
327
+ "execution_count": 20,
328
+ "id": "8d7e21ef",
329
+ "metadata": {},
330
+ "outputs": [
331
+ {
332
+ "data": {
333
+ "text/html": [
334
+ "<div>\n",
335
+ "<style scoped>\n",
336
+ " .dataframe tbody tr th:only-of-type {\n",
337
+ " vertical-align: middle;\n",
338
+ " }\n",
339
+ "\n",
340
+ " .dataframe tbody tr th {\n",
341
+ " vertical-align: top;\n",
342
+ " }\n",
343
+ "\n",
344
+ " .dataframe thead th {\n",
345
+ " text-align: right;\n",
346
+ " }\n",
347
+ "</style>\n",
348
+ "<table border=\"1\" class=\"dataframe\">\n",
349
+ " <thead>\n",
350
+ " <tr style=\"text-align: right;\">\n",
351
+ " <th></th>\n",
352
+ " <th>0</th>\n",
353
+ " <th>1</th>\n",
354
+ " <th>2</th>\n",
355
+ " </tr>\n",
356
+ " </thead>\n",
357
+ " <tbody>\n",
358
+ " <tr>\n",
359
+ " <th>0</th>\n",
360
+ " <td>1.0</td>\n",
361
+ " <td>NaN</td>\n",
362
+ " <td>2</td>\n",
363
+ " </tr>\n",
364
+ " <tr>\n",
365
+ " <th>1</th>\n",
366
+ " <td>2.0</td>\n",
367
+ " <td>3.0</td>\n",
368
+ " <td>5</td>\n",
369
+ " </tr>\n",
370
+ " <tr>\n",
371
+ " <th>2</th>\n",
372
+ " <td>NaN</td>\n",
373
+ " <td>4.0</td>\n",
374
+ " <td>6</td>\n",
375
+ " </tr>\n",
376
+ " </tbody>\n",
377
+ "</table>\n",
378
+ "</div>"
379
+ ],
380
+ "text/plain": [
381
+ " 0 1 2\n",
382
+ "0 1.0 NaN 2\n",
383
+ "1 2.0 3.0 5\n",
384
+ "2 NaN 4.0 6"
385
+ ]
386
+ },
387
+ "execution_count": 20,
388
+ "metadata": {},
389
+ "output_type": "execute_result"
390
+ }
391
+ ],
392
+ "source": [
393
+ "df = pd.DataFrame([[1, np.nan, 2],\n",
394
+ " [2, 3, 5],\n",
395
+ " [np.nan, 4, 6]])\n",
396
+ "df\n"
397
+ ]
398
+ },
399
+ {
400
+ "cell_type": "code",
401
+ "execution_count": 21,
402
+ "id": "3355043d",
403
+ "metadata": {},
404
+ "outputs": [
405
+ {
406
+ "data": {
407
+ "text/html": [
408
+ "<div>\n",
409
+ "<style scoped>\n",
410
+ " .dataframe tbody tr th:only-of-type {\n",
411
+ " vertical-align: middle;\n",
412
+ " }\n",
413
+ "\n",
414
+ " .dataframe tbody tr th {\n",
415
+ " vertical-align: top;\n",
416
+ " }\n",
417
+ "\n",
418
+ " .dataframe thead th {\n",
419
+ " text-align: right;\n",
420
+ " }\n",
421
+ "</style>\n",
422
+ "<table border=\"1\" class=\"dataframe\">\n",
423
+ " <thead>\n",
424
+ " <tr style=\"text-align: right;\">\n",
425
+ " <th></th>\n",
426
+ " <th>0</th>\n",
427
+ " <th>1</th>\n",
428
+ " <th>2</th>\n",
429
+ " </tr>\n",
430
+ " </thead>\n",
431
+ " <tbody>\n",
432
+ " <tr>\n",
433
+ " <th>1</th>\n",
434
+ " <td>2.0</td>\n",
435
+ " <td>3.0</td>\n",
436
+ " <td>5</td>\n",
437
+ " </tr>\n",
438
+ " </tbody>\n",
439
+ "</table>\n",
440
+ "</div>"
441
+ ],
442
+ "text/plain": [
443
+ " 0 1 2\n",
444
+ "1 2.0 3.0 5"
445
+ ]
446
+ },
447
+ "execution_count": 21,
448
+ "metadata": {},
449
+ "output_type": "execute_result"
450
+ }
451
+ ],
452
+ "source": [
453
+ "df.dropna()"
454
+ ]
455
+ },
456
+ {
457
+ "cell_type": "code",
458
+ "execution_count": 22,
459
+ "id": "c3c7920b",
460
+ "metadata": {},
461
+ "outputs": [
462
+ {
463
+ "data": {
464
+ "text/html": [
465
+ "<div>\n",
466
+ "<style scoped>\n",
467
+ " .dataframe tbody tr th:only-of-type {\n",
468
+ " vertical-align: middle;\n",
469
+ " }\n",
470
+ "\n",
471
+ " .dataframe tbody tr th {\n",
472
+ " vertical-align: top;\n",
473
+ " }\n",
474
+ "\n",
475
+ " .dataframe thead th {\n",
476
+ " text-align: right;\n",
477
+ " }\n",
478
+ "</style>\n",
479
+ "<table border=\"1\" class=\"dataframe\">\n",
480
+ " <thead>\n",
481
+ " <tr style=\"text-align: right;\">\n",
482
+ " <th></th>\n",
483
+ " <th>2</th>\n",
484
+ " </tr>\n",
485
+ " </thead>\n",
486
+ " <tbody>\n",
487
+ " <tr>\n",
488
+ " <th>0</th>\n",
489
+ " <td>2</td>\n",
490
+ " </tr>\n",
491
+ " <tr>\n",
492
+ " <th>1</th>\n",
493
+ " <td>5</td>\n",
494
+ " </tr>\n",
495
+ " <tr>\n",
496
+ " <th>2</th>\n",
497
+ " <td>6</td>\n",
498
+ " </tr>\n",
499
+ " </tbody>\n",
500
+ "</table>\n",
501
+ "</div>"
502
+ ],
503
+ "text/plain": [
504
+ " 2\n",
505
+ "0 2\n",
506
+ "1 5\n",
507
+ "2 6"
508
+ ]
509
+ },
510
+ "execution_count": 22,
511
+ "metadata": {},
512
+ "output_type": "execute_result"
513
+ }
514
+ ],
515
+ "source": [
516
+ "df.dropna(axis='columns')"
517
+ ]
518
+ },
519
+ {
520
+ "cell_type": "code",
521
+ "execution_count": 23,
522
+ "id": "d987a577",
523
+ "metadata": {},
524
+ "outputs": [
525
+ {
526
+ "data": {
527
+ "text/html": [
528
+ "<div>\n",
529
+ "<style scoped>\n",
530
+ " .dataframe tbody tr th:only-of-type {\n",
531
+ " vertical-align: middle;\n",
532
+ " }\n",
533
+ "\n",
534
+ " .dataframe tbody tr th {\n",
535
+ " vertical-align: top;\n",
536
+ " }\n",
537
+ "\n",
538
+ " .dataframe thead th {\n",
539
+ " text-align: right;\n",
540
+ " }\n",
541
+ "</style>\n",
542
+ "<table border=\"1\" class=\"dataframe\">\n",
543
+ " <thead>\n",
544
+ " <tr style=\"text-align: right;\">\n",
545
+ " <th></th>\n",
546
+ " <th>0</th>\n",
547
+ " <th>1</th>\n",
548
+ " <th>2</th>\n",
549
+ " <th>3</th>\n",
550
+ " </tr>\n",
551
+ " </thead>\n",
552
+ " <tbody>\n",
553
+ " <tr>\n",
554
+ " <th>0</th>\n",
555
+ " <td>1.0</td>\n",
556
+ " <td>NaN</td>\n",
557
+ " <td>2</td>\n",
558
+ " <td>NaN</td>\n",
559
+ " </tr>\n",
560
+ " <tr>\n",
561
+ " <th>1</th>\n",
562
+ " <td>2.0</td>\n",
563
+ " <td>3.0</td>\n",
564
+ " <td>5</td>\n",
565
+ " <td>NaN</td>\n",
566
+ " </tr>\n",
567
+ " <tr>\n",
568
+ " <th>2</th>\n",
569
+ " <td>NaN</td>\n",
570
+ " <td>4.0</td>\n",
571
+ " <td>6</td>\n",
572
+ " <td>NaN</td>\n",
573
+ " </tr>\n",
574
+ " </tbody>\n",
575
+ "</table>\n",
576
+ "</div>"
577
+ ],
578
+ "text/plain": [
579
+ " 0 1 2 3\n",
580
+ "0 1.0 NaN 2 NaN\n",
581
+ "1 2.0 3.0 5 NaN\n",
582
+ "2 NaN 4.0 6 NaN"
583
+ ]
584
+ },
585
+ "execution_count": 23,
586
+ "metadata": {},
587
+ "output_type": "execute_result"
588
+ }
589
+ ],
590
+ "source": [
591
+ "df[3] = np.nan\n",
592
+ "df"
593
+ ]
594
+ },
595
+ {
596
+ "cell_type": "code",
597
+ "execution_count": 24,
598
+ "id": "5fa2e884",
599
+ "metadata": {},
600
+ "outputs": [
601
+ {
602
+ "data": {
603
+ "text/html": [
604
+ "<div>\n",
605
+ "<style scoped>\n",
606
+ " .dataframe tbody tr th:only-of-type {\n",
607
+ " vertical-align: middle;\n",
608
+ " }\n",
609
+ "\n",
610
+ " .dataframe tbody tr th {\n",
611
+ " vertical-align: top;\n",
612
+ " }\n",
613
+ "\n",
614
+ " .dataframe thead th {\n",
615
+ " text-align: right;\n",
616
+ " }\n",
617
+ "</style>\n",
618
+ "<table border=\"1\" class=\"dataframe\">\n",
619
+ " <thead>\n",
620
+ " <tr style=\"text-align: right;\">\n",
621
+ " <th></th>\n",
622
+ " <th>0</th>\n",
623
+ " <th>1</th>\n",
624
+ " <th>2</th>\n",
625
+ " </tr>\n",
626
+ " </thead>\n",
627
+ " <tbody>\n",
628
+ " <tr>\n",
629
+ " <th>0</th>\n",
630
+ " <td>1.0</td>\n",
631
+ " <td>NaN</td>\n",
632
+ " <td>2</td>\n",
633
+ " </tr>\n",
634
+ " <tr>\n",
635
+ " <th>1</th>\n",
636
+ " <td>2.0</td>\n",
637
+ " <td>3.0</td>\n",
638
+ " <td>5</td>\n",
639
+ " </tr>\n",
640
+ " <tr>\n",
641
+ " <th>2</th>\n",
642
+ " <td>NaN</td>\n",
643
+ " <td>4.0</td>\n",
644
+ " <td>6</td>\n",
645
+ " </tr>\n",
646
+ " </tbody>\n",
647
+ "</table>\n",
648
+ "</div>"
649
+ ],
650
+ "text/plain": [
651
+ " 0 1 2\n",
652
+ "0 1.0 NaN 2\n",
653
+ "1 2.0 3.0 5\n",
654
+ "2 NaN 4.0 6"
655
+ ]
656
+ },
657
+ "execution_count": 24,
658
+ "metadata": {},
659
+ "output_type": "execute_result"
660
+ }
661
+ ],
662
+ "source": [
663
+ "df.dropna(axis='columns', how='all')"
664
+ ]
665
+ },
666
+ {
667
+ "cell_type": "code",
668
+ "execution_count": 25,
669
+ "id": "2b62a4d7",
670
+ "metadata": {},
671
+ "outputs": [
672
+ {
673
+ "data": {
674
+ "text/html": [
675
+ "<div>\n",
676
+ "<style scoped>\n",
677
+ " .dataframe tbody tr th:only-of-type {\n",
678
+ " vertical-align: middle;\n",
679
+ " }\n",
680
+ "\n",
681
+ " .dataframe tbody tr th {\n",
682
+ " vertical-align: top;\n",
683
+ " }\n",
684
+ "\n",
685
+ " .dataframe thead th {\n",
686
+ " text-align: right;\n",
687
+ " }\n",
688
+ "</style>\n",
689
+ "<table border=\"1\" class=\"dataframe\">\n",
690
+ " <thead>\n",
691
+ " <tr style=\"text-align: right;\">\n",
692
+ " <th></th>\n",
693
+ " <th>0</th>\n",
694
+ " <th>1</th>\n",
695
+ " <th>2</th>\n",
696
+ " <th>3</th>\n",
697
+ " </tr>\n",
698
+ " </thead>\n",
699
+ " <tbody>\n",
700
+ " <tr>\n",
701
+ " <th>1</th>\n",
702
+ " <td>2.0</td>\n",
703
+ " <td>3.0</td>\n",
704
+ " <td>5</td>\n",
705
+ " <td>NaN</td>\n",
706
+ " </tr>\n",
707
+ " </tbody>\n",
708
+ "</table>\n",
709
+ "</div>"
710
+ ],
711
+ "text/plain": [
712
+ " 0 1 2 3\n",
713
+ "1 2.0 3.0 5 NaN"
714
+ ]
715
+ },
716
+ "execution_count": 25,
717
+ "metadata": {},
718
+ "output_type": "execute_result"
719
+ }
720
+ ],
721
+ "source": [
722
+ "df.dropna(axis='rows', thresh=3)\n"
723
+ ]
724
+ },
725
+ {
726
+ "cell_type": "code",
727
+ "execution_count": 26,
728
+ "id": "ab65fccd",
729
+ "metadata": {},
730
+ "outputs": [
731
+ {
732
+ "data": {
733
+ "text/plain": [
734
+ "a 1.0\n",
735
+ "b NaN\n",
736
+ "c 2.0\n",
737
+ "d NaN\n",
738
+ "e 3.0\n",
739
+ "dtype: float64"
740
+ ]
741
+ },
742
+ "execution_count": 26,
743
+ "metadata": {},
744
+ "output_type": "execute_result"
745
+ }
746
+ ],
747
+ "source": [
748
+ "#Filling null values\n",
749
+ "data = pd.Series([1, np.nan, 2, None, 3], index=list('abcde'))\n",
750
+ "data"
751
+ ]
752
+ },
753
+ {
754
+ "cell_type": "code",
755
+ "execution_count": 27,
756
+ "id": "79701b50",
757
+ "metadata": {},
758
+ "outputs": [
759
+ {
760
+ "data": {
761
+ "text/plain": [
762
+ "a 1.0\n",
763
+ "b 0.0\n",
764
+ "c 2.0\n",
765
+ "d 0.0\n",
766
+ "e 3.0\n",
767
+ "dtype: float64"
768
+ ]
769
+ },
770
+ "execution_count": 27,
771
+ "metadata": {},
772
+ "output_type": "execute_result"
773
+ }
774
+ ],
775
+ "source": [
776
+ "data.fillna(0)"
777
+ ]
778
+ },
779
+ {
780
+ "cell_type": "code",
781
+ "execution_count": 28,
782
+ "id": "e2920e55",
783
+ "metadata": {},
784
+ "outputs": [
785
+ {
786
+ "data": {
787
+ "text/plain": [
788
+ "a 1.0\n",
789
+ "b 1.0\n",
790
+ "c 2.0\n",
791
+ "d 2.0\n",
792
+ "e 3.0\n",
793
+ "dtype: float64"
794
+ ]
795
+ },
796
+ "execution_count": 28,
797
+ "metadata": {},
798
+ "output_type": "execute_result"
799
+ }
800
+ ],
801
+ "source": [
802
+ "# forward-fill\n",
803
+ "data.fillna(method='ffill')"
804
+ ]
805
+ },
806
+ {
807
+ "cell_type": "code",
808
+ "execution_count": 30,
809
+ "id": "057ad778",
810
+ "metadata": {},
811
+ "outputs": [
812
+ {
813
+ "data": {
814
+ "text/plain": [
815
+ "a 1.0\n",
816
+ "b 2.0\n",
817
+ "c 2.0\n",
818
+ "d 3.0\n",
819
+ "e 3.0\n",
820
+ "dtype: float64"
821
+ ]
822
+ },
823
+ "execution_count": 30,
824
+ "metadata": {},
825
+ "output_type": "execute_result"
826
+ }
827
+ ],
828
+ "source": [
829
+ "# back-fill\n",
830
+ "data.fillna(method='bfill')\n"
831
+ ]
832
+ },
833
+ {
834
+ "cell_type": "code",
835
+ "execution_count": 31,
836
+ "id": "1d99ee5b",
837
+ "metadata": {},
838
+ "outputs": [
839
+ {
840
+ "data": {
841
+ "text/html": [
842
+ "<div>\n",
843
+ "<style scoped>\n",
844
+ " .dataframe tbody tr th:only-of-type {\n",
845
+ " vertical-align: middle;\n",
846
+ " }\n",
847
+ "\n",
848
+ " .dataframe tbody tr th {\n",
849
+ " vertical-align: top;\n",
850
+ " }\n",
851
+ "\n",
852
+ " .dataframe thead th {\n",
853
+ " text-align: right;\n",
854
+ " }\n",
855
+ "</style>\n",
856
+ "<table border=\"1\" class=\"dataframe\">\n",
857
+ " <thead>\n",
858
+ " <tr style=\"text-align: right;\">\n",
859
+ " <th></th>\n",
860
+ " <th>0</th>\n",
861
+ " <th>1</th>\n",
862
+ " <th>2</th>\n",
863
+ " <th>3</th>\n",
864
+ " </tr>\n",
865
+ " </thead>\n",
866
+ " <tbody>\n",
867
+ " <tr>\n",
868
+ " <th>0</th>\n",
869
+ " <td>1.0</td>\n",
870
+ " <td>NaN</td>\n",
871
+ " <td>2</td>\n",
872
+ " <td>NaN</td>\n",
873
+ " </tr>\n",
874
+ " <tr>\n",
875
+ " <th>1</th>\n",
876
+ " <td>2.0</td>\n",
877
+ " <td>3.0</td>\n",
878
+ " <td>5</td>\n",
879
+ " <td>NaN</td>\n",
880
+ " </tr>\n",
881
+ " <tr>\n",
882
+ " <th>2</th>\n",
883
+ " <td>NaN</td>\n",
884
+ " <td>4.0</td>\n",
885
+ " <td>6</td>\n",
886
+ " <td>NaN</td>\n",
887
+ " </tr>\n",
888
+ " </tbody>\n",
889
+ "</table>\n",
890
+ "</div>"
891
+ ],
892
+ "text/plain": [
893
+ " 0 1 2 3\n",
894
+ "0 1.0 NaN 2 NaN\n",
895
+ "1 2.0 3.0 5 NaN\n",
896
+ "2 NaN 4.0 6 NaN"
897
+ ]
898
+ },
899
+ "execution_count": 31,
900
+ "metadata": {},
901
+ "output_type": "execute_result"
902
+ }
903
+ ],
904
+ "source": [
905
+ "df"
906
+ ]
907
+ },
908
+ {
909
+ "cell_type": "code",
910
+ "execution_count": 32,
911
+ "id": "a5e51c61",
912
+ "metadata": {},
913
+ "outputs": [
914
+ {
915
+ "data": {
916
+ "text/html": [
917
+ "<div>\n",
918
+ "<style scoped>\n",
919
+ " .dataframe tbody tr th:only-of-type {\n",
920
+ " vertical-align: middle;\n",
921
+ " }\n",
922
+ "\n",
923
+ " .dataframe tbody tr th {\n",
924
+ " vertical-align: top;\n",
925
+ " }\n",
926
+ "\n",
927
+ " .dataframe thead th {\n",
928
+ " text-align: right;\n",
929
+ " }\n",
930
+ "</style>\n",
931
+ "<table border=\"1\" class=\"dataframe\">\n",
932
+ " <thead>\n",
933
+ " <tr style=\"text-align: right;\">\n",
934
+ " <th></th>\n",
935
+ " <th>0</th>\n",
936
+ " <th>1</th>\n",
937
+ " <th>2</th>\n",
938
+ " <th>3</th>\n",
939
+ " </tr>\n",
940
+ " </thead>\n",
941
+ " <tbody>\n",
942
+ " <tr>\n",
943
+ " <th>0</th>\n",
944
+ " <td>1.0</td>\n",
945
+ " <td>1.0</td>\n",
946
+ " <td>2.0</td>\n",
947
+ " <td>2.0</td>\n",
948
+ " </tr>\n",
949
+ " <tr>\n",
950
+ " <th>1</th>\n",
951
+ " <td>2.0</td>\n",
952
+ " <td>3.0</td>\n",
953
+ " <td>5.0</td>\n",
954
+ " <td>5.0</td>\n",
955
+ " </tr>\n",
956
+ " <tr>\n",
957
+ " <th>2</th>\n",
958
+ " <td>NaN</td>\n",
959
+ " <td>4.0</td>\n",
960
+ " <td>6.0</td>\n",
961
+ " <td>6.0</td>\n",
962
+ " </tr>\n",
963
+ " </tbody>\n",
964
+ "</table>\n",
965
+ "</div>"
966
+ ],
967
+ "text/plain": [
968
+ " 0 1 2 3\n",
969
+ "0 1.0 1.0 2.0 2.0\n",
970
+ "1 2.0 3.0 5.0 5.0\n",
971
+ "2 NaN 4.0 6.0 6.0"
972
+ ]
973
+ },
974
+ "execution_count": 32,
975
+ "metadata": {},
976
+ "output_type": "execute_result"
977
+ }
978
+ ],
979
+ "source": [
980
+ "df.fillna(method='ffill', axis=1)"
981
+ ]
982
+ },
983
+ {
984
+ "cell_type": "code",
985
+ "execution_count": null,
986
+ "id": "1ae8ebbc",
987
+ "metadata": {},
988
+ "outputs": [],
989
+ "source": []
990
+ }
991
+ ],
992
+ "metadata": {
993
+ "kernelspec": {
994
+ "display_name": "Python 3 (ipykernel)",
995
+ "language": "python",
996
+ "name": "python3"
997
+ },
998
+ "language_info": {
999
+ "codemirror_mode": {
1000
+ "name": "ipython",
1001
+ "version": 3
1002
+ },
1003
+ "file_extension": ".py",
1004
+ "mimetype": "text/x-python",
1005
+ "name": "python",
1006
+ "nbconvert_exporter": "python",
1007
+ "pygments_lexer": "ipython3",
1008
+ "version": "3.9.13"
1009
+ }
1010
+ },
1011
+ "nbformat": 4,
1012
+ "nbformat_minor": 5
1013
+ }