Format: application/octet-stream
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 12,
6 "id": "3f9478a2",
7 "metadata": {},
8 "outputs": [],
9 "source": [
10 "l= [x for x in range(1,10001) if x%7==0 and x%13==0 and x%17==0]\n",
11 "d= dict(zip(range(1,len(l)+1), l))"
12 ]
13 },
14 {
15 "cell_type": "code",
16 "execution_count": 13,
17 "id": "705698d8",
18 "metadata": {},
19 "outputs": [
20 {
21 "data": {
22 "text/plain": [
23 "{1: 1547, 2: 3094, 3: 4641, 4: 6188, 5: 7735, 6: 9282}"
24 ]
25 },
26 "execution_count": 13,
27 "metadata": {},
28 "output_type": "execute_result"
29 }
30 ],
31 "source": [
32 "d"
33 ]
34 },
35 {
36 "cell_type": "code",
37 "execution_count": 14,
38 "id": "4f207803",
39 "metadata": {},
40 "outputs": [
41 {
42 "data": {
43 "text/plain": [
44 "1547"
45 ]
46 },
47 "execution_count": 14,
48 "metadata": {},
49 "output_type": "execute_result"
50 }
51 ],
52 "source": [
53 "d[1]"
54 ]
55 },
56 {
57 "cell_type": "code",
58 "execution_count": 18,
59 "id": "4c65152d",
60 "metadata": {},
61 "outputs": [
62 {
63 "data": {
64 "text/plain": [
65 "1547"
66 ]
67 },
68 "execution_count": 18,
69 "metadata": {},
70 "output_type": "execute_result"
71 }
72 ],
73 "source": [
74 "d.pop(1)"
75 ]
76 },
77 {
78 "cell_type": "code",
79 "execution_count": 25,
80 "id": "aad60de3",
81 "metadata": {},
82 "outputs": [
83 {
84 "data": {
85 "text/plain": [
86 "(6, 9282)"
87 ]
88 },
89 "execution_count": 25,
90 "metadata": {},
91 "output_type": "execute_result"
92 }
93 ],
94 "source": [
95 "d.popitem()"
96 ]
97 },
98 {
99 "cell_type": "code",
100 "execution_count": 30,
101 "id": "5d252eee",
102 "metadata": {},
103 "outputs": [
104 {
105 "data": {
106 "text/plain": [
107 "dict_values([3094, 4641, 6188, 7735])"
108 ]
109 },
110 "execution_count": 30,
111 "metadata": {},
112 "output_type": "execute_result"
113 }
114 ],
115 "source": [
116 "d.values()"
117 ]
118 },
119 {
120 "cell_type": "code",
121 "execution_count": 31,
122 "id": "6d6b917f",
123 "metadata": {},
124 "outputs": [],
125 "source": [
126 "s= 'hi hhow are you'"
127 ]
128 },
129 {
130 "cell_type": "code",
131 "execution_count": 32,
132 "id": "f64654dc",
133 "metadata": {},
134 "outputs": [
135 {
136 "data": {
137 "text/plain": [
138 "'Hi Hhow Are You'"
139 ]
140 },
141 "execution_count": 32,
142 "metadata": {},
143 "output_type": "execute_result"
144 }
145 ],
146 "source": [
147 "s.title()"
148 ]
149 },
150 {
151 "cell_type": "code",
152 "execution_count": 33,
153 "id": "707b10fb",
154 "metadata": {},
155 "outputs": [
156 {
157 "data": {
158 "text/plain": [
159 "4"
160 ]
161 },
162 "execution_count": 33,
163 "metadata": {},
164 "output_type": "execute_result"
165 }
166 ],
167 "source": [
168 "len(s.split(' '))"
169 ]
170 },
171 {
172 "cell_type": "code",
173 "execution_count": 34,
174 "id": "4f9621b5",
175 "metadata": {},
176 "outputs": [
177 {
178 "data": {
179 "text/plain": [
180 "15"
181 ]
182 },
183 "execution_count": 34,
184 "metadata": {},
185 "output_type": "execute_result"
186 }
187 ],
188 "source": [
189 "len(s)"
190 ]
191 },
192 {
193 "cell_type": "code",
194 "execution_count": 36,
195 "id": "08a23ac4",
196 "metadata": {},
197 "outputs": [],
198 "source": [
199 "l=list(s)"
200 ]
201 },
202 {
203 "cell_type": "code",
204 "execution_count": 37,
205 "id": "6e659aec",
206 "metadata": {},
207 "outputs": [
208 {
209 "data": {
210 "text/plain": [
211 "['h', 'i', ' ', 'h', 'h', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u']"
212 ]
213 },
214 "execution_count": 37,
215 "metadata": {},
216 "output_type": "execute_result"
217 }
218 ],
219 "source": [
220 "l"
221 ]
222 },
223 {
224 "cell_type": "code",
225 "execution_count": 61,
226 "id": "823ad731",
227 "metadata": {},
228 "outputs": [],
229 "source": [
230 "d = {\n",
231 " \"name\": \"Dog\",\n",
232 " \"age\":5,\n",
233 " \"Weight\": 4,\n",
234 " \"Country\": \"US\",\n",
235 " \"City\":\"California\"\n",
236 " \n",
237 "}\n"
238 ]
239 },
240 {
241 "cell_type": "code",
242 "execution_count": 40,
243 "id": "0ae9c1d3",
244 "metadata": {},
245 "outputs": [
246 {
247 "data": {
248 "text/plain": [
249 "{'name': 'Dog', 'age': 5}"
250 ]
251 },
252 "execution_count": 40,
253 "metadata": {},
254 "output_type": "execute_result"
255 }
256 ],
257 "source": [
258 "dict(zip(['name', 'age'], [d['name'], d['age']]))"
259 ]
260 },
261 {
262 "cell_type": "code",
263 "execution_count": 45,
264 "id": "c49970f2",
265 "metadata": {},
266 "outputs": [],
267 "source": [
268 "del d['name'], d['age']"
269 ]
270 },
271 {
272 "cell_type": "code",
273 "execution_count": null,
274 "id": "a00ff2b9",
275 "metadata": {},
276 "outputs": [],
277 "source": []
278 },
279 {
280 "cell_type": "code",
281 "execution_count": 69,
282 "id": "e672e044",
283 "metadata": {},
284 "outputs": [],
285 "source": [
286 "d= {'b':5,'a':1,'D':4}"
287 ]
288 },
289 {
290 "cell_type": "code",
291 "execution_count": 59,
292 "id": "adc7b70f",
293 "metadata": {},
294 "outputs": [
295 {
296 "name": "stdout",
297 "output_type": "stream",
298 "text": [
299 "4\n",
300 "1\n",
301 "5\n"
302 ]
303 }
304 ],
305 "source": [
306 "for _ in sorted(d):\n",
307 " print(d[_])"
308 ]
309 },
310 {
311 "cell_type": "code",
312 "execution_count": 60,
313 "id": "d39a70a6",
314 "metadata": {},
315 "outputs": [
316 {
317 "data": {
318 "text/plain": [
319 "2550608643392"
320 ]
321 },
322 "execution_count": 60,
323 "metadata": {},
324 "output_type": "execute_result"
325 }
326 ],
327 "source": [
328 "id(d)"
329 ]
330 },
331 {
332 "cell_type": "code",
333 "execution_count": 62,
334 "id": "3d559509",
335 "metadata": {},
336 "outputs": [],
337 "source": [
338 "d['animalname']= d.pop('name')"
339 ]
340 },
341 {
342 "cell_type": "code",
343 "execution_count": 63,
344 "id": "6628f948",
345 "metadata": {},
346 "outputs": [
347 {
348 "data": {
349 "text/plain": [
350 "{'age': 5,\n",
351 " 'Weight': 4,\n",
352 " 'Country': 'US',\n",
353 " 'City': 'California',\n",
354 " 'animalname': 'Dog'}"
355 ]
356 },
357 "execution_count": 63,
358 "metadata": {},
359 "output_type": "execute_result"
360 }
361 ],
362 "source": [
363 "d"
364 ]
365 },
366 {
367 "cell_type": "code",
368 "execution_count": 65,
369 "id": "0f60311e",
370 "metadata": {},
371 "outputs": [
372 {
373 "ename": "TypeError",
374 "evalue": "unhashable type: 'list'",
375 "output_type": "error",
376 "traceback": [
377 "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
378 "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)",
379 "\u001b[1;32m<ipython-input-65-fa3104c36ec4>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0md\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'age'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'animalname'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
380 "\u001b[1;31mTypeError\u001b[0m: unhashable type: 'list'"
381 ]
382 }
383 ],
384 "source": [
385 "d[['age','animalname']]"
386 ]
387 },
388 {
389 "cell_type": "code",
390 "execution_count": 67,
391 "id": "5214f1cd",
392 "metadata": {},
393 "outputs": [],
394 "source": [
395 "if 'age' in d:\n",
396 " del d['age']"
397 ]
398 },
399 {
400 "cell_type": "code",
401 "execution_count": 68,
402 "id": "4764dc47",
403 "metadata": {},
404 "outputs": [
405 {
406 "data": {
407 "text/plain": [
408 "{'Weight': 4, 'Country': 'US', 'City': 'California', 'animalname': 'Dog'}"
409 ]
410 },
411 "execution_count": 68,
412 "metadata": {},
413 "output_type": "execute_result"
414 }
415 ],
416 "source": [
417 "d"
418 ]
419 },
420 {
421 "cell_type": "code",
422 "execution_count": 74,
423 "id": "d2d353a4",
424 "metadata": {},
425 "outputs": [],
426 "source": [
427 "d.get?"
428 ]
429 },
430 {
431 "cell_type": "code",
432 "execution_count": 76,
433 "id": "55cd11f0",
434 "metadata": {},
435 "outputs": [
436 {
437 "data": {
438 "text/plain": [
439 "'a'"
440 ]
441 },
442 "execution_count": 76,
443 "metadata": {},
444 "output_type": "execute_result"
445 }
446 ],
447 "source": [
448 "min(d, key= d.get)"
449 ]
450 },
451 {
452 "cell_type": "code",
453 "execution_count": 77,
454 "id": "1794e90a",
455 "metadata": {},
456 "outputs": [
457 {
458 "data": {
459 "text/plain": [
460 "{'b': 5, 'a': 1, 'D': 4}"
461 ]
462 },
463 "execution_count": 77,
464 "metadata": {},
465 "output_type": "execute_result"
466 }
467 ],
468 "source": [
469 "d"
470 ]
471 },
472 {
473 "cell_type": "code",
474 "execution_count": 80,
475 "id": "978b9baa",
476 "metadata": {},
477 "outputs": [
478 {
479 "data": {
480 "text/plain": [
481 "['b', 'D']"
482 ]
483 },
484 "execution_count": 80,
485 "metadata": {},
486 "output_type": "execute_result"
487 }
488 ],
489 "source": [
490 "sorted(d, key= d.get,reverse=1)[:2]"
491 ]
492 },
493 {
494 "cell_type": "code",
495 "execution_count": null,
496 "id": "2c18c380",
497 "metadata": {},
498 "outputs": [],
499 "source": []
500 },
501 {
502 "cell_type": "code",
503 "execution_count": 94,
504 "id": "30546ded",
505 "metadata": {},
506 "outputs": [],
507 "source": [
508 "d= {'Fr uit':['Apple','Banana','Orange'],'Sub ject':['Phy','Math','English']}"
509 ]
510 },
511 {
512 "cell_type": "code",
513 "execution_count": 96,
514 "id": "635fd51f",
515 "metadata": {},
516 "outputs": [
517 {
518 "data": {
519 "text/plain": [
520 "{'Fruit': ['Apple', 'Banana', 'Orange'], 'Subject': ['Phy', 'Math', 'English']}"
521 ]
522 },
523 "execution_count": 96,
524 "metadata": {},
525 "output_type": "execute_result"
526 }
527 ],
528 "source": [
529 "{x.replace(' ',''):d[x] for x in d.keys()}"
530 ]
531 },
532 {
533 "cell_type": "code",
534 "execution_count": 97,
535 "id": "fde90bad",
536 "metadata": {},
537 "outputs": [],
538 "source": [
539 "d = {'lang': 'C#', 'Fruit': 'Apple', 'Subj':None,'Animal':None}\n"
540 ]
541 },
542 {
543 "cell_type": "code",
544 "execution_count": 100,
545 "id": "0a63b8ef",
546 "metadata": {},
547 "outputs": [
548 {
549 "data": {
550 "text/plain": [
551 "{'lang': 'C#', 'Fruit': 'Apple'}"
552 ]
553 },
554 "execution_count": 100,
555 "metadata": {},
556 "output_type": "execute_result"
557 }
558 ],
559 "source": [
560 "{i: j for i,j in d.items() if j != None}"
561 ]
562 },
563 {
564 "cell_type": "code",
565 "execution_count": 101,
566 "id": "eb8a70b7",
567 "metadata": {},
568 "outputs": [],
569 "source": [
570 "d={'Racx': 12000, 'Max':80000,'Stack':80000,'John':80000,}\n"
571 ]
572 },
573 {
574 "cell_type": "code",
575 "execution_count": 104,
576 "id": "1e330628",
577 "metadata": {},
578 "outputs": [
579 {
580 "data": {
581 "text/plain": [
582 "{12000: 1, 80000: 3}"
583 ]
584 },
585 "execution_count": 104,
586 "metadata": {},
587 "output_type": "execute_result"
588 }
589 ],
590 "source": [
591 "{x : list(d.values()).count(x) for x in set(d.values())}"
592 ]
593 },
594 {
595 "cell_type": "code",
596 "execution_count": null,
597 "id": "049ccf87",
598 "metadata": {},
599 "outputs": [],
600 "source": []
601 },
602 {
603 "cell_type": "code",
604 "execution_count": null,
605 "id": "c879dd63",
606 "metadata": {},
607 "outputs": [],
608 "source": []
609 },
610 {
611 "cell_type": "code",
612 "execution_count": 105,
613 "id": "4d8f5676",
614 "metadata": {},
615 "outputs": [],
616 "source": [
617 "s= 'hi how are you'"
618 ]
619 },
620 {
621 "cell_type": "code",
622 "execution_count": 109,
623 "id": "d8f99af6",
624 "metadata": {},
625 "outputs": [
626 {
627 "data": {
628 "text/plain": [
629 "'you are how hi'"
630 ]
631 },
632 "execution_count": 109,
633 "metadata": {},
634 "output_type": "execute_result"
635 }
636 ],
637 "source": [
638 "' '.join(reversed(s.split(' ')))"
639 ]
640 },
641 {
642 "cell_type": "code",
643 "execution_count": 115,
644 "id": "793155a1",
645 "metadata": {},
646 "outputs": [
647 {
648 "data": {
649 "text/plain": [
650 "['h', ' ', 'o', ' ', 'r', ' ', 'o']"
651 ]
652 },
653 "execution_count": 115,
654 "metadata": {},
655 "output_type": "execute_result"
656 }
657 ],
658 "source": [
659 "[s[i] for i in range(len(s)) if i%2==0]"
660 ]
661 },
662 {
663 "cell_type": "code",
664 "execution_count": 116,
665 "id": "75a1a127",
666 "metadata": {},
667 "outputs": [
668 {
669 "data": {
670 "text/plain": [
671 "True"
672 ]
673 },
674 "execution_count": 116,
675 "metadata": {},
676 "output_type": "execute_result"
677 }
678 ],
679 "source": [
680 "s.startswith('hi')"
681 ]
682 },
683 {
684 "cell_type": "code",
685 "execution_count": 117,
686 "id": "119dfc8c",
687 "metadata": {},
688 "outputs": [
689 {
690 "data": {
691 "text/plain": [
692 "False"
693 ]
694 },
695 "execution_count": 117,
696 "metadata": {},
697 "output_type": "execute_result"
698 }
699 ],
700 "source": [
701 "s.endswith('bye')"
702 ]
703 },
704 {
705 "cell_type": "code",
706 "execution_count": 124,
707 "id": "e2758806",
708 "metadata": {},
709 "outputs": [],
710 "source": [
711 "s= '\\nPython String\\n with\\n newline\\n'\n"
712 ]
713 },
714 {
715 "cell_type": "code",
716 "execution_count": 126,
717 "id": "24704d80",
718 "metadata": {},
719 "outputs": [
720 {
721 "name": "stdout",
722 "output_type": "stream",
723 "text": [
724 "\n",
725 "Python String\n",
726 " with\n",
727 " newline\n",
728 "\n"
729 ]
730 }
731 ],
732 "source": [
733 "print(s)"
734 ]
735 },
736 {
737 "cell_type": "code",
738 "execution_count": 1,
739 "id": "c2497629",
740 "metadata": {},
741 "outputs": [],
742 "source": [
743 "s1 = \"Let us Learn Python\"\n",
744 "s2 = \"PythonProgram\""
745 ]
746 },
747 {
748 "cell_type": "code",
749 "execution_count": 2,
750 "id": "05535293",
751 "metadata": {},
752 "outputs": [
753 {
754 "data": {
755 "text/plain": [
756 "{' ', 'L', 'P', 'a', 'e', 'h', 'n', 'o', 'r', 's', 't', 'u', 'y'}"
757 ]
758 },
759 "execution_count": 2,
760 "metadata": {},
761 "output_type": "execute_result"
762 }
763 ],
764 "source": [
765 "set(s1)"
766 ]
767 },
768 {
769 "cell_type": "code",
770 "execution_count": 5,
771 "id": "2f29243a",
772 "metadata": {},
773 "outputs": [
774 {
775 "data": {
776 "text/plain": [
777 "'leT uS learN pythoN'"
778 ]
779 },
780 "execution_count": 5,
781 "metadata": {},
782 "output_type": "execute_result"
783 }
784 ],
785 "source": [
786 "''.join(reversed(''.join(reversed(s1)).title()))"
787 ]
788 },
789 {
790 "cell_type": "code",
791 "execution_count": 134,
792 "id": "736366dd",
793 "metadata": {},
794 "outputs": [
795 {
796 "data": {
797 "text/plain": [
798 "9"
799 ]
800 },
801 "execution_count": 134,
802 "metadata": {},
803 "output_type": "execute_result"
804 }
805 ],
806 "source": [
807 "len([x for x in set(s1) if x in set(s2)])"
808 ]
809 },
810 {
811 "cell_type": "code",
812 "execution_count": 138,
813 "id": "d6813d4e",
814 "metadata": {},
815 "outputs": [
816 {
817 "data": {
818 "text/plain": [
819 "['Python', 'is', 'Amazing']"
820 ]
821 },
822 "execution_count": 138,
823 "metadata": {},
824 "output_type": "execute_result"
825 }
826 ],
827 "source": [
828 "s1.split(' ')"
829 ]
830 },
831 {
832 "cell_type": "code",
833 "execution_count": 6,
834 "id": "960c6527",
835 "metadata": {},
836 "outputs": [
837 {
838 "data": {
839 "text/plain": [
840 "[False,\n",
841 " True,\n",
842 " True,\n",
843 " False,\n",
844 " True,\n",
845 " True,\n",
846 " False,\n",
847 " False,\n",
848 " True,\n",
849 " True,\n",
850 " True,\n",
851 " True,\n",
852 " False,\n",
853 " False,\n",
854 " True,\n",
855 " True,\n",
856 " True,\n",
857 " True,\n",
858 " True]"
859 ]
860 },
861 "execution_count": 6,
862 "metadata": {},
863 "output_type": "execute_result"
864 }
865 ],
866 "source": [
867 "[x.islower() for x in list(s1)]"
868 ]
869 },
870 {
871 "cell_type": "code",
872 "execution_count": 13,
873 "id": "a70f7cd6",
874 "metadata": {},
875 "outputs": [],
876 "source": [
877 "l= sum([x.islower() for x in s1])\n",
878 "u = sum([x.isupper() for x in list(s1)])"
879 ]
880 },
881 {
882 "cell_type": "code",
883 "execution_count": 14,
884 "id": "fd60d4f9",
885 "metadata": {},
886 "outputs": [
887 {
888 "data": {
889 "text/plain": [
890 "13"
891 ]
892 },
893 "execution_count": 14,
894 "metadata": {},
895 "output_type": "execute_result"
896 }
897 ],
898 "source": [
899 "l"
900 ]
901 },
902 {
903 "cell_type": "code",
904 "execution_count": 15,
905 "id": "09eeaf1c",
906 "metadata": {},
907 "outputs": [
908 {
909 "data": {
910 "text/plain": [
911 "3"
912 ]
913 },
914 "execution_count": 15,
915 "metadata": {},
916 "output_type": "execute_result"
917 }
918 ],
919 "source": [
920 "u"
921 ]
922 },
923 {
924 "cell_type": "code",
925 "execution_count": 12,
926 "id": "da8ed039",
927 "metadata": {},
928 "outputs": [
929 {
930 "data": {
931 "text/plain": [
932 "11"
933 ]
934 },
935 "execution_count": 12,
936 "metadata": {},
937 "output_type": "execute_result"
938 }
939 ],
940 "source": [
941 "len([x for x in s1 if x not in 'aeiouAEIOU ' ])"
942 ]
943 },
944 {
945 "cell_type": "code",
946 "execution_count": null,
947 "id": "201f0d10",
948 "metadata": {},
949 "outputs": [],
950 "source": []
951 },
952 {
953 "cell_type": "code",
954 "execution_count": null,
955 "id": "5c77a73f",
956 "metadata": {},
957 "outputs": [],
958 "source": []
959 },
960 {
961 "cell_type": "code",
962 "execution_count": 19,
963 "id": "a57c91c0",
964 "metadata": {},
965 "outputs": [],
966 "source": [
967 "l= [['tom',10], ['mary',12], ['k',13], ['bernard',9]]"
968 ]
969 },
970 {
971 "cell_type": "code",
972 "execution_count": 20,
973 "id": "47fc74a1",
974 "metadata": {},
975 "outputs": [],
976 "source": [
977 "import pandas as pd"
978 ]
979 },
980 {
981 "cell_type": "code",
982 "execution_count": 23,
983 "id": "18c896c7",
984 "metadata": {},
985 "outputs": [],
986 "source": [
987 "df= pd.DataFrame(l, columns=['name', 'age'])"
988 ]
989 },
990 {
991 "cell_type": "code",
992 "execution_count": 24,
993 "id": "76ba22f1",
994 "metadata": {},
995 "outputs": [
996 {
997 "data": {
998 "text/html": [
999 "<div>\n",
1000 "<style scoped>\n",
1001 " .dataframe tbody tr th:only-of-type {\n",
1002 " vertical-align: middle;\n",
1003 " }\n",
1004 "\n",
1005 " .dataframe tbody tr th {\n",
1006 " vertical-align: top;\n",
1007 " }\n",
1008 "\n",
1009 " .dataframe thead th {\n",
1010 " text-align: right;\n",
1011 " }\n",
1012 "</style>\n",
1013 "<table border=\"1\" class=\"dataframe\">\n",
1014 " <thead>\n",
1015 " <tr style=\"text-align: right;\">\n",
1016 " <th></th>\n",
1017 " <th>Name</th>\n",
1018 " <th>Age</th>\n",
1019 " </tr>\n",
1020 " </thead>\n",
1021 " <tbody>\n",
1022 " <tr>\n",
1023 " <th>0</th>\n",
1024 " <td>tom</td>\n",
1025 " <td>10</td>\n",
1026 " </tr>\n",
1027 " <tr>\n",
1028 " <th>1</th>\n",
1029 " <td>mary</td>\n",
1030 " <td>12</td>\n",
1031 " </tr>\n",
1032 " <tr>\n",
1033 " <th>2</th>\n",
1034 " <td>k</td>\n",
1035 " <td>13</td>\n",
1036 " </tr>\n",
1037 " <tr>\n",
1038 " <th>3</th>\n",
1039 " <td>bernard</td>\n",
1040 " <td>9</td>\n",
1041 " </tr>\n",
1042 " </tbody>\n",
1043 "</table>\n",
1044 "</div>"
1045 ],
1046 "text/plain": [
1047 " Name Age\n",
1048 "0 tom 10\n",
1049 "1 mary 12\n",
1050 "2 k 13\n",
1051 "3 bernard 9"
1052 ]
1053 },
1054 "execution_count": 24,
1055 "metadata": {},
1056 "output_type": "execute_result"
1057 }
1058 ],
1059 "source": [
1060 "df.rename(columns={'name':'Name', 'age':'Age'})"
1061 ]
1062 },
1063 {
1064 "cell_type": "code",
1065 "execution_count": 25,
1066 "id": "25cf15ab",
1067 "metadata": {},
1068 "outputs": [
1069 {
1070 "data": {
1071 "text/html": [
1072 "<div>\n",
1073 "<style scoped>\n",
1074 " .dataframe tbody tr th:only-of-type {\n",
1075 " vertical-align: middle;\n",
1076 " }\n",
1077 "\n",
1078 " .dataframe tbody tr th {\n",
1079 " vertical-align: top;\n",
1080 " }\n",
1081 "\n",
1082 " .dataframe thead th {\n",
1083 " text-align: right;\n",
1084 " }\n",
1085 "</style>\n",
1086 "<table border=\"1\" class=\"dataframe\">\n",
1087 " <thead>\n",
1088 " <tr style=\"text-align: right;\">\n",
1089 " <th></th>\n",
1090 " <th>age</th>\n",
1091 " </tr>\n",
1092 " <tr>\n",
1093 " <th>name</th>\n",
1094 " <th></th>\n",
1095 " </tr>\n",
1096 " </thead>\n",
1097 " <tbody>\n",
1098 " <tr>\n",
1099 " <th>tom</th>\n",
1100 " <td>10</td>\n",
1101 " </tr>\n",
1102 " <tr>\n",
1103 " <th>mary</th>\n",
1104 " <td>12</td>\n",
1105 " </tr>\n",
1106 " <tr>\n",
1107 " <th>k</th>\n",
1108 " <td>13</td>\n",
1109 " </tr>\n",
1110 " <tr>\n",
1111 " <th>bernard</th>\n",
1112 " <td>9</td>\n",
1113 " </tr>\n",
1114 " </tbody>\n",
1115 "</table>\n",
1116 "</div>"
1117 ],
1118 "text/plain": [
1119 " age\n",
1120 "name \n",
1121 "tom 10\n",
1122 "mary 12\n",
1123 "k 13\n",
1124 "bernard 9"
1125 ]
1126 },
1127 "execution_count": 25,
1128 "metadata": {},
1129 "output_type": "execute_result"
1130 }
1131 ],
1132 "source": [
1133 "df.set_index('name')"
1134 ]
1135 },
1136 {
1137 "cell_type": "code",
1138 "execution_count": 27,
1139 "id": "d4e9e4f8",
1140 "metadata": {},
1141 "outputs": [
1142 {
1143 "data": {
1144 "text/html": [
1145 "<div>\n",
1146 "<style scoped>\n",
1147 " .dataframe tbody tr th:only-of-type {\n",
1148 " vertical-align: middle;\n",
1149 " }\n",
1150 "\n",
1151 " .dataframe tbody tr th {\n",
1152 " vertical-align: top;\n",
1153 " }\n",
1154 "\n",
1155 " .dataframe thead th {\n",
1156 " text-align: right;\n",
1157 " }\n",
1158 "</style>\n",
1159 "<table border=\"1\" class=\"dataframe\">\n",
1160 " <thead>\n",
1161 " <tr style=\"text-align: right;\">\n",
1162 " <th></th>\n",
1163 " <th>name</th>\n",
1164 " <th>age</th>\n",
1165 " </tr>\n",
1166 " </thead>\n",
1167 " <tbody>\n",
1168 " <tr>\n",
1169 " <th>2</th>\n",
1170 " <td>k</td>\n",
1171 " <td>13</td>\n",
1172 " </tr>\n",
1173 " </tbody>\n",
1174 "</table>\n",
1175 "</div>"
1176 ],
1177 "text/plain": [
1178 " name age\n",
1179 "2 k 13"
1180 ]
1181 },
1182 "execution_count": 27,
1183 "metadata": {},
1184 "output_type": "execute_result"
1185 }
1186 ],
1187 "source": [
1188 "df[(df.age> df.age.mean()) & (df.name!='mary')]"
1189 ]
1190 },
1191 {
1192 "cell_type": "code",
1193 "execution_count": 28,
1194 "id": "689a83f3",
1195 "metadata": {},
1196 "outputs": [],
1197 "source": [
1198 "s=[ ['tom', 500] , ['jack', 600], ['mary', 350], ['j',400] ]"
1199 ]
1200 },
1201 {
1202 "cell_type": "code",
1203 "execution_count": 29,
1204 "id": "fee75e4e",
1205 "metadata": {},
1206 "outputs": [],
1207 "source": [
1208 "dfs= pd.DataFrame(s, columns= ['name', 'salary'])"
1209 ]
1210 },
1211 {
1212 "cell_type": "code",
1213 "execution_count": 30,
1214 "id": "c5cd443b",
1215 "metadata": {},
1216 "outputs": [
1217 {
1218 "data": {
1219 "text/html": [
1220 "<div>\n",
1221 "<style scoped>\n",
1222 " .dataframe tbody tr th:only-of-type {\n",
1223 " vertical-align: middle;\n",
1224 " }\n",
1225 "\n",
1226 " .dataframe tbody tr th {\n",
1227 " vertical-align: top;\n",
1228 " }\n",
1229 "\n",
1230 " .dataframe thead th {\n",
1231 " text-align: right;\n",
1232 " }\n",
1233 "</style>\n",
1234 "<table border=\"1\" class=\"dataframe\">\n",
1235 " <thead>\n",
1236 " <tr style=\"text-align: right;\">\n",
1237 " <th></th>\n",
1238 " <th>name</th>\n",
1239 " <th>salary</th>\n",
1240 " </tr>\n",
1241 " </thead>\n",
1242 " <tbody>\n",
1243 " <tr>\n",
1244 " <th>0</th>\n",
1245 " <td>tom</td>\n",
1246 " <td>500</td>\n",
1247 " </tr>\n",
1248 " <tr>\n",
1249 " <th>1</th>\n",
1250 " <td>jack</td>\n",
1251 " <td>600</td>\n",
1252 " </tr>\n",
1253 " <tr>\n",
1254 " <th>2</th>\n",
1255 " <td>mary</td>\n",
1256 " <td>350</td>\n",
1257 " </tr>\n",
1258 " <tr>\n",
1259 " <th>3</th>\n",
1260 " <td>j</td>\n",
1261 " <td>400</td>\n",
1262 " </tr>\n",
1263 " </tbody>\n",
1264 "</table>\n",
1265 "</div>"
1266 ],
1267 "text/plain": [
1268 " name salary\n",
1269 "0 tom 500\n",
1270 "1 jack 600\n",
1271 "2 mary 350\n",
1272 "3 j 400"
1273 ]
1274 },
1275 "execution_count": 30,
1276 "metadata": {},
1277 "output_type": "execute_result"
1278 }
1279 ],
1280 "source": [
1281 "dfs"
1282 ]
1283 },
1284 {
1285 "cell_type": "code",
1286 "execution_count": 31,
1287 "id": "f618f508",
1288 "metadata": {},
1289 "outputs": [
1290 {
1291 "data": {
1292 "text/html": [
1293 "<div>\n",
1294 "<style scoped>\n",
1295 " .dataframe tbody tr th:only-of-type {\n",
1296 " vertical-align: middle;\n",
1297 " }\n",
1298 "\n",
1299 " .dataframe tbody tr th {\n",
1300 " vertical-align: top;\n",
1301 " }\n",
1302 "\n",
1303 " .dataframe thead th {\n",
1304 " text-align: right;\n",
1305 " }\n",
1306 "</style>\n",
1307 "<table border=\"1\" class=\"dataframe\">\n",
1308 " <thead>\n",
1309 " <tr style=\"text-align: right;\">\n",
1310 " <th></th>\n",
1311 " <th>name</th>\n",
1312 " <th>age</th>\n",
1313 " <th>salary</th>\n",
1314 " </tr>\n",
1315 " </thead>\n",
1316 " <tbody>\n",
1317 " <tr>\n",
1318 " <th>0</th>\n",
1319 " <td>tom</td>\n",
1320 " <td>10</td>\n",
1321 " <td>500</td>\n",
1322 " </tr>\n",
1323 " <tr>\n",
1324 " <th>1</th>\n",
1325 " <td>mary</td>\n",
1326 " <td>12</td>\n",
1327 " <td>350</td>\n",
1328 " </tr>\n",
1329 " </tbody>\n",
1330 "</table>\n",
1331 "</div>"
1332 ],
1333 "text/plain": [
1334 " name age salary\n",
1335 "0 tom 10 500\n",
1336 "1 mary 12 350"
1337 ]
1338 },
1339 "execution_count": 31,
1340 "metadata": {},
1341 "output_type": "execute_result"
1342 }
1343 ],
1344 "source": [
1345 "df.merge(dfs)"
1346 ]
1347 },
1348 {
1349 "cell_type": "code",
1350 "execution_count": 32,
1351 "id": "da8f6fb3",
1352 "metadata": {},
1353 "outputs": [
1354 {
1355 "data": {
1356 "text/html": [
1357 "<div>\n",
1358 "<style scoped>\n",
1359 " .dataframe tbody tr th:only-of-type {\n",
1360 " vertical-align: middle;\n",
1361 " }\n",
1362 "\n",
1363 " .dataframe tbody tr th {\n",
1364 " vertical-align: top;\n",
1365 " }\n",
1366 "\n",
1367 " .dataframe thead th {\n",
1368 " text-align: right;\n",
1369 " }\n",
1370 "</style>\n",
1371 "<table border=\"1\" class=\"dataframe\">\n",
1372 " <thead>\n",
1373 " <tr style=\"text-align: right;\">\n",
1374 " <th></th>\n",
1375 " <th>name</th>\n",
1376 " <th>age</th>\n",
1377 " <th>salary</th>\n",
1378 " </tr>\n",
1379 " </thead>\n",
1380 " <tbody>\n",
1381 " <tr>\n",
1382 " <th>0</th>\n",
1383 " <td>tom</td>\n",
1384 " <td>10</td>\n",
1385 " <td>500.0</td>\n",
1386 " </tr>\n",
1387 " <tr>\n",
1388 " <th>1</th>\n",
1389 " <td>mary</td>\n",
1390 " <td>12</td>\n",
1391 " <td>350.0</td>\n",
1392 " </tr>\n",
1393 " <tr>\n",
1394 " <th>2</th>\n",
1395 " <td>k</td>\n",
1396 " <td>13</td>\n",
1397 " <td>NaN</td>\n",
1398 " </tr>\n",
1399 " <tr>\n",
1400 " <th>3</th>\n",
1401 " <td>bernard</td>\n",
1402 " <td>9</td>\n",
1403 " <td>NaN</td>\n",
1404 " </tr>\n",
1405 " </tbody>\n",
1406 "</table>\n",
1407 "</div>"
1408 ],
1409 "text/plain": [
1410 " name age salary\n",
1411 "0 tom 10 500.0\n",
1412 "1 mary 12 350.0\n",
1413 "2 k 13 NaN\n",
1414 "3 bernard 9 NaN"
1415 ]
1416 },
1417 "execution_count": 32,
1418 "metadata": {},
1419 "output_type": "execute_result"
1420 }
1421 ],
1422 "source": [
1423 "df.merge(dfs, how='left')"
1424 ]
1425 },
1426 {
1427 "cell_type": "code",
1428 "execution_count": 33,
1429 "id": "b71361ba",
1430 "metadata": {},
1431 "outputs": [
1432 {
1433 "data": {
1434 "text/html": [
1435 "<div>\n",
1436 "<style scoped>\n",
1437 " .dataframe tbody tr th:only-of-type {\n",
1438 " vertical-align: middle;\n",
1439 " }\n",
1440 "\n",
1441 " .dataframe tbody tr th {\n",
1442 " vertical-align: top;\n",
1443 " }\n",
1444 "\n",
1445 " .dataframe thead th {\n",
1446 " text-align: right;\n",
1447 " }\n",
1448 "</style>\n",
1449 "<table border=\"1\" class=\"dataframe\">\n",
1450 " <thead>\n",
1451 " <tr style=\"text-align: right;\">\n",
1452 " <th></th>\n",
1453 " <th>name</th>\n",
1454 " <th>age</th>\n",
1455 " <th>salary</th>\n",
1456 " </tr>\n",
1457 " </thead>\n",
1458 " <tbody>\n",
1459 " <tr>\n",
1460 " <th>0</th>\n",
1461 " <td>tom</td>\n",
1462 " <td>10.0</td>\n",
1463 " <td>500</td>\n",
1464 " </tr>\n",
1465 " <tr>\n",
1466 " <th>1</th>\n",
1467 " <td>jack</td>\n",
1468 " <td>NaN</td>\n",
1469 " <td>600</td>\n",
1470 " </tr>\n",
1471 " <tr>\n",
1472 " <th>2</th>\n",
1473 " <td>mary</td>\n",
1474 " <td>12.0</td>\n",
1475 " <td>350</td>\n",
1476 " </tr>\n",
1477 " <tr>\n",
1478 " <th>3</th>\n",
1479 " <td>j</td>\n",
1480 " <td>NaN</td>\n",
1481 " <td>400</td>\n",
1482 " </tr>\n",
1483 " </tbody>\n",
1484 "</table>\n",
1485 "</div>"
1486 ],
1487 "text/plain": [
1488 " name age salary\n",
1489 "0 tom 10.0 500\n",
1490 "1 jack NaN 600\n",
1491 "2 mary 12.0 350\n",
1492 "3 j NaN 400"
1493 ]
1494 },
1495 "execution_count": 33,
1496 "metadata": {},
1497 "output_type": "execute_result"
1498 }
1499 ],
1500 "source": [
1501 "df.merge(dfs, how='right')"
1502 ]
1503 },
1504 {
1505 "cell_type": "code",
1506 "execution_count": 35,
1507 "id": "eb4c363d",
1508 "metadata": {},
1509 "outputs": [
1510 {
1511 "data": {
1512 "text/html": [
1513 "<div>\n",
1514 "<style scoped>\n",
1515 " .dataframe tbody tr th:only-of-type {\n",
1516 " vertical-align: middle;\n",
1517 " }\n",
1518 "\n",
1519 " .dataframe tbody tr th {\n",
1520 " vertical-align: top;\n",
1521 " }\n",
1522 "\n",
1523 " .dataframe thead th {\n",
1524 " text-align: right;\n",
1525 " }\n",
1526 "</style>\n",
1527 "<table border=\"1\" class=\"dataframe\">\n",
1528 " <thead>\n",
1529 " <tr style=\"text-align: right;\">\n",
1530 " <th></th>\n",
1531 " <th>name</th>\n",
1532 " <th>age</th>\n",
1533 " <th>salary</th>\n",
1534 " </tr>\n",
1535 " </thead>\n",
1536 " <tbody>\n",
1537 " <tr>\n",
1538 " <th>0</th>\n",
1539 " <td>tom</td>\n",
1540 " <td>10.0</td>\n",
1541 " <td>500.0</td>\n",
1542 " </tr>\n",
1543 " <tr>\n",
1544 " <th>1</th>\n",
1545 " <td>mary</td>\n",
1546 " <td>12.0</td>\n",
1547 " <td>350.0</td>\n",
1548 " </tr>\n",
1549 " <tr>\n",
1550 " <th>2</th>\n",
1551 " <td>k</td>\n",
1552 " <td>13.0</td>\n",
1553 " <td>NaN</td>\n",
1554 " </tr>\n",
1555 " <tr>\n",
1556 " <th>3</th>\n",
1557 " <td>bernard</td>\n",
1558 " <td>9.0</td>\n",
1559 " <td>NaN</td>\n",
1560 " </tr>\n",
1561 " <tr>\n",
1562 " <th>4</th>\n",
1563 " <td>jack</td>\n",
1564 " <td>NaN</td>\n",
1565 " <td>600.0</td>\n",
1566 " </tr>\n",
1567 " <tr>\n",
1568 " <th>5</th>\n",
1569 " <td>j</td>\n",
1570 " <td>NaN</td>\n",
1571 " <td>400.0</td>\n",
1572 " </tr>\n",
1573 " </tbody>\n",
1574 "</table>\n",
1575 "</div>"
1576 ],
1577 "text/plain": [
1578 " name age salary\n",
1579 "0 tom 10.0 500.0\n",
1580 "1 mary 12.0 350.0\n",
1581 "2 k 13.0 NaN\n",
1582 "3 bernard 9.0 NaN\n",
1583 "4 jack NaN 600.0\n",
1584 "5 j NaN 400.0"
1585 ]
1586 },
1587 "execution_count": 35,
1588 "metadata": {},
1589 "output_type": "execute_result"
1590 }
1591 ],
1592 "source": [
1593 "df.merge(dfs, how='outer')"
1594 ]
1595 },
1596 {
1597 "cell_type": "code",
1598 "execution_count": 37,
1599 "id": "9a655eab",
1600 "metadata": {},
1601 "outputs": [],
1602 "source": [
1603 "df= df.merge(dfs, how='outer')"
1604 ]
1605 },
1606 {
1607 "cell_type": "code",
1608 "execution_count": 40,
1609 "id": "ede21e4b",
1610 "metadata": {},
1611 "outputs": [
1612 {
1613 "data": {
1614 "text/plain": [
1615 "name 0\n",
1616 "age 2\n",
1617 "salary 2\n",
1618 "dtype: int64"
1619 ]
1620 },
1621 "execution_count": 40,
1622 "metadata": {},
1623 "output_type": "execute_result"
1624 }
1625 ],
1626 "source": [
1627 "df.isna().sum()"
1628 ]
1629 },
1630 {
1631 "cell_type": "code",
1632 "execution_count": 41,
1633 "id": "9b50917d",
1634 "metadata": {},
1635 "outputs": [
1636 {
1637 "data": {
1638 "text/html": [
1639 "<div>\n",
1640 "<style scoped>\n",
1641 " .dataframe tbody tr th:only-of-type {\n",
1642 " vertical-align: middle;\n",
1643 " }\n",
1644 "\n",
1645 " .dataframe tbody tr th {\n",
1646 " vertical-align: top;\n",
1647 " }\n",
1648 "\n",
1649 " .dataframe thead th {\n",
1650 " text-align: right;\n",
1651 " }\n",
1652 "</style>\n",
1653 "<table border=\"1\" class=\"dataframe\">\n",
1654 " <thead>\n",
1655 " <tr style=\"text-align: right;\">\n",
1656 " <th></th>\n",
1657 " <th>name</th>\n",
1658 " <th>age</th>\n",
1659 " <th>salary</th>\n",
1660 " </tr>\n",
1661 " </thead>\n",
1662 " <tbody>\n",
1663 " <tr>\n",
1664 " <th>0</th>\n",
1665 " <td>tom</td>\n",
1666 " <td>10.0</td>\n",
1667 " <td>500.0</td>\n",
1668 " </tr>\n",
1669 " <tr>\n",
1670 " <th>1</th>\n",
1671 " <td>mary</td>\n",
1672 " <td>12.0</td>\n",
1673 " <td>350.0</td>\n",
1674 " </tr>\n",
1675 " <tr>\n",
1676 " <th>2</th>\n",
1677 " <td>k</td>\n",
1678 " <td>13.0</td>\n",
1679 " <td>NaN</td>\n",
1680 " </tr>\n",
1681 " <tr>\n",
1682 " <th>3</th>\n",
1683 " <td>bernard</td>\n",
1684 " <td>9.0</td>\n",
1685 " <td>NaN</td>\n",
1686 " </tr>\n",
1687 " <tr>\n",
1688 " <th>4</th>\n",
1689 " <td>jack</td>\n",
1690 " <td>NaN</td>\n",
1691 " <td>600.0</td>\n",
1692 " </tr>\n",
1693 " <tr>\n",
1694 " <th>5</th>\n",
1695 " <td>j</td>\n",
1696 " <td>NaN</td>\n",
1697 " <td>400.0</td>\n",
1698 " </tr>\n",
1699 " </tbody>\n",
1700 "</table>\n",
1701 "</div>"
1702 ],
1703 "text/plain": [
1704 " name age salary\n",
1705 "0 tom 10.0 500.0\n",
1706 "1 mary 12.0 350.0\n",
1707 "2 k 13.0 NaN\n",
1708 "3 bernard 9.0 NaN\n",
1709 "4 jack NaN 600.0\n",
1710 "5 j NaN 400.0"
1711 ]
1712 },
1713 "execution_count": 41,
1714 "metadata": {},
1715 "output_type": "execute_result"
1716 }
1717 ],
1718 "source": [
1719 "df"
1720 ]
1721 },
1722 {
1723 "cell_type": "code",
1724 "execution_count": 44,
1725 "id": "74c26fc9",
1726 "metadata": {},
1727 "outputs": [
1728 {
1729 "data": {
1730 "text/html": [
1731 "<div>\n",
1732 "<style scoped>\n",
1733 " .dataframe tbody tr th:only-of-type {\n",
1734 " vertical-align: middle;\n",
1735 " }\n",
1736 "\n",
1737 " .dataframe tbody tr th {\n",
1738 " vertical-align: top;\n",
1739 " }\n",
1740 "\n",
1741 " .dataframe thead th {\n",
1742 " text-align: right;\n",
1743 " }\n",
1744 "</style>\n",
1745 "<table border=\"1\" class=\"dataframe\">\n",
1746 " <thead>\n",
1747 " <tr style=\"text-align: right;\">\n",
1748 " <th></th>\n",
1749 " <th>name</th>\n",
1750 " <th>salary</th>\n",
1751 " </tr>\n",
1752 " </thead>\n",
1753 " <tbody>\n",
1754 " <tr>\n",
1755 " <th>0</th>\n",
1756 " <td>tom</td>\n",
1757 " <td>500.0</td>\n",
1758 " </tr>\n",
1759 " <tr>\n",
1760 " <th>1</th>\n",
1761 " <td>mary</td>\n",
1762 " <td>350.0</td>\n",
1763 " </tr>\n",
1764 " <tr>\n",
1765 " <th>2</th>\n",
1766 " <td>k</td>\n",
1767 " <td>NaN</td>\n",
1768 " </tr>\n",
1769 " <tr>\n",
1770 " <th>3</th>\n",
1771 " <td>bernard</td>\n",
1772 " <td>NaN</td>\n",
1773 " </tr>\n",
1774 " <tr>\n",
1775 " <th>4</th>\n",
1776 " <td>jack</td>\n",
1777 " <td>600.0</td>\n",
1778 " </tr>\n",
1779 " <tr>\n",
1780 " <th>5</th>\n",
1781 " <td>j</td>\n",
1782 " <td>400.0</td>\n",
1783 " </tr>\n",
1784 " </tbody>\n",
1785 "</table>\n",
1786 "</div>"
1787 ],
1788 "text/plain": [
1789 " name salary\n",
1790 "0 tom 500.0\n",
1791 "1 mary 350.0\n",
1792 "2 k NaN\n",
1793 "3 bernard NaN\n",
1794 "4 jack 600.0\n",
1795 "5 j 400.0"
1796 ]
1797 },
1798 "execution_count": 44,
1799 "metadata": {},
1800 "output_type": "execute_result"
1801 }
1802 ],
1803 "source": [
1804 "df.drop(columns=['age'])"
1805 ]
1806 },
1807 {
1808 "cell_type": "code",
1809 "execution_count": 45,
1810 "id": "ba1737bb",
1811 "metadata": {},
1812 "outputs": [
1813 {
1814 "data": {
1815 "text/html": [
1816 "<div>\n",
1817 "<style scoped>\n",
1818 " .dataframe tbody tr th:only-of-type {\n",
1819 " vertical-align: middle;\n",
1820 " }\n",
1821 "\n",
1822 " .dataframe tbody tr th {\n",
1823 " vertical-align: top;\n",
1824 " }\n",
1825 "\n",
1826 " .dataframe thead th {\n",
1827 " text-align: right;\n",
1828 " }\n",
1829 "</style>\n",
1830 "<table border=\"1\" class=\"dataframe\">\n",
1831 " <thead>\n",
1832 " <tr style=\"text-align: right;\">\n",
1833 " <th></th>\n",
1834 " <th>name</th>\n",
1835 " <th>age</th>\n",
1836 " <th>salary</th>\n",
1837 " </tr>\n",
1838 " </thead>\n",
1839 " <tbody>\n",
1840 " <tr>\n",
1841 " <th>3</th>\n",
1842 " <td>bernard</td>\n",
1843 " <td>9.0</td>\n",
1844 " <td>NaN</td>\n",
1845 " </tr>\n",
1846 " <tr>\n",
1847 " <th>0</th>\n",
1848 " <td>tom</td>\n",
1849 " <td>10.0</td>\n",
1850 " <td>500.0</td>\n",
1851 " </tr>\n",
1852 " <tr>\n",
1853 " <th>1</th>\n",
1854 " <td>mary</td>\n",
1855 " <td>12.0</td>\n",
1856 " <td>350.0</td>\n",
1857 " </tr>\n",
1858 " <tr>\n",
1859 " <th>2</th>\n",
1860 " <td>k</td>\n",
1861 " <td>13.0</td>\n",
1862 " <td>NaN</td>\n",
1863 " </tr>\n",
1864 " <tr>\n",
1865 " <th>4</th>\n",
1866 " <td>jack</td>\n",
1867 " <td>NaN</td>\n",
1868 " <td>600.0</td>\n",
1869 " </tr>\n",
1870 " <tr>\n",
1871 " <th>5</th>\n",
1872 " <td>j</td>\n",
1873 " <td>NaN</td>\n",
1874 " <td>400.0</td>\n",
1875 " </tr>\n",
1876 " </tbody>\n",
1877 "</table>\n",
1878 "</div>"
1879 ],
1880 "text/plain": [
1881 " name age salary\n",
1882 "3 bernard 9.0 NaN\n",
1883 "0 tom 10.0 500.0\n",
1884 "1 mary 12.0 350.0\n",
1885 "2 k 13.0 NaN\n",
1886 "4 jack NaN 600.0\n",
1887 "5 j NaN 400.0"
1888 ]
1889 },
1890 "execution_count": 45,
1891 "metadata": {},
1892 "output_type": "execute_result"
1893 }
1894 ],
1895 "source": [
1896 "df.sort_values(by='age')"
1897 ]
1898 },
1899 {
1900 "cell_type": "code",
1901 "execution_count": 48,
1902 "id": "6b4f4d36",
1903 "metadata": {},
1904 "outputs": [],
1905 "source": [
1906 "df.fillna(df.mean(), inplace= True)"
1907 ]
1908 },
1909 {
1910 "cell_type": "code",
1911 "execution_count": 49,
1912 "id": "ccefc052",
1913 "metadata": {},
1914 "outputs": [
1915 {
1916 "data": {
1917 "text/html": [
1918 "<div>\n",
1919 "<style scoped>\n",
1920 " .dataframe tbody tr th:only-of-type {\n",
1921 " vertical-align: middle;\n",
1922 " }\n",
1923 "\n",
1924 " .dataframe tbody tr th {\n",
1925 " vertical-align: top;\n",
1926 " }\n",
1927 "\n",
1928 " .dataframe thead th {\n",
1929 " text-align: right;\n",
1930 " }\n",
1931 "</style>\n",
1932 "<table border=\"1\" class=\"dataframe\">\n",
1933 " <thead>\n",
1934 " <tr style=\"text-align: right;\">\n",
1935 " <th></th>\n",
1936 " <th>age</th>\n",
1937 " <th>salary</th>\n",
1938 " </tr>\n",
1939 " <tr>\n",
1940 " <th>name</th>\n",
1941 " <th></th>\n",
1942 " <th></th>\n",
1943 " </tr>\n",
1944 " </thead>\n",
1945 " <tbody>\n",
1946 " <tr>\n",
1947 " <th>bernard</th>\n",
1948 " <td>9.0</td>\n",
1949 " <td>462.5</td>\n",
1950 " </tr>\n",
1951 " <tr>\n",
1952 " <th>j</th>\n",
1953 " <td>11.0</td>\n",
1954 " <td>400.0</td>\n",
1955 " </tr>\n",
1956 " <tr>\n",
1957 " <th>jack</th>\n",
1958 " <td>11.0</td>\n",
1959 " <td>600.0</td>\n",
1960 " </tr>\n",
1961 " <tr>\n",
1962 " <th>k</th>\n",
1963 " <td>13.0</td>\n",
1964 " <td>462.5</td>\n",
1965 " </tr>\n",
1966 " <tr>\n",
1967 " <th>mary</th>\n",
1968 " <td>12.0</td>\n",
1969 " <td>350.0</td>\n",
1970 " </tr>\n",
1971 " <tr>\n",
1972 " <th>tom</th>\n",
1973 " <td>10.0</td>\n",
1974 " <td>500.0</td>\n",
1975 " </tr>\n",
1976 " </tbody>\n",
1977 "</table>\n",
1978 "</div>"
1979 ],
1980 "text/plain": [
1981 " age salary\n",
1982 "name \n",
1983 "bernard 9.0 462.5\n",
1984 "j 11.0 400.0\n",
1985 "jack 11.0 600.0\n",
1986 "k 13.0 462.5\n",
1987 "mary 12.0 350.0\n",
1988 "tom 10.0 500.0"
1989 ]
1990 },
1991 "execution_count": 49,
1992 "metadata": {},
1993 "output_type": "execute_result"
1994 }
1995 ],
1996 "source": [
1997 "df.set_index('name').sort_index()"
1998 ]
1999 },
2000 {
2001 "cell_type": "code",
2002 "execution_count": 50,
2003 "id": "3dc3e217",
2004 "metadata": {},
2005 "outputs": [
2006 {
2007 "data": {
2008 "text/html": [
2009 "<div>\n",
2010 "<style scoped>\n",
2011 " .dataframe tbody tr th:only-of-type {\n",
2012 " vertical-align: middle;\n",
2013 " }\n",
2014 "\n",
2015 " .dataframe tbody tr th {\n",
2016 " vertical-align: top;\n",
2017 " }\n",
2018 "\n",
2019 " .dataframe thead th {\n",
2020 " text-align: right;\n",
2021 " }\n",
2022 "</style>\n",
2023 "<table border=\"1\" class=\"dataframe\">\n",
2024 " <thead>\n",
2025 " <tr style=\"text-align: right;\">\n",
2026 " <th></th>\n",
2027 " <th>name</th>\n",
2028 " <th>age</th>\n",
2029 " <th>salary</th>\n",
2030 " </tr>\n",
2031 " </thead>\n",
2032 " <tbody>\n",
2033 " <tr>\n",
2034 " <th>1</th>\n",
2035 " <td>mary</td>\n",
2036 " <td>12.0</td>\n",
2037 " <td>350.0</td>\n",
2038 " </tr>\n",
2039 " </tbody>\n",
2040 "</table>\n",
2041 "</div>"
2042 ],
2043 "text/plain": [
2044 " name age salary\n",
2045 "1 mary 12.0 350.0"
2046 ]
2047 },
2048 "execution_count": 50,
2049 "metadata": {},
2050 "output_type": "execute_result"
2051 }
2052 ],
2053 "source": [
2054 "df[(df.age>df.age.mean()) & (df.salary< df.salary.mean())]"
2055 ]
2056 },
2057 {
2058 "cell_type": "code",
2059 "execution_count": null,
2060 "id": "f432d5ee",
2061 "metadata": {},
2062 "outputs": [],
2063 "source": []
2064 }
2065 ],
2066 "metadata": {
2067 "kernelspec": {
2068 "display_name": "Python 3",
2069 "language": "python",
2070 "name": "python3"
2071 },
2072 "language_info": {
2073 "codemirror_mode": {
2074 "name": "ipython",
2075 "version": 3
2076 },
2077 "file_extension": ".py",
2078 "mimetype": "text/x-python",
2079 "name": "python",
2080 "nbconvert_exporter": "python",
2081 "pygments_lexer": "ipython3",
2082 "version": "3.8.8"
2083 }
2084 },
2085 "nbformat": 4,
2086 "nbformat_minor": 5
2087 }
2088