1 00:00:00,480 --> 00:00:06,460 Welcome back to the class of our course about the complete introduction to that science with Python. 2 00:00:06,960 --> 00:00:11,850 So in this class, we are still going to talk about pandas and some basic operations that you guys can 3 00:00:11,850 --> 00:00:15,160 perform with this amazing plug in to Python. 4 00:00:15,990 --> 00:00:22,140 So basically today we are going to learn how to merge some data frames together and what exactly means 5 00:00:22,140 --> 00:00:22,510 merge. 6 00:00:22,530 --> 00:00:23,280 It's pretty simple. 7 00:00:23,280 --> 00:00:25,860 It's let's say, for example, you guys have more than one that frame. 8 00:00:25,860 --> 00:00:31,150 So let's say two, three or four, dereference you can put them together in only one data frame. 9 00:00:31,170 --> 00:00:36,120 So basically, if each of those that are frames are the same, so there is the same thing written on 10 00:00:36,120 --> 00:00:40,430 them, you can just put them all together and only one data frame. 11 00:00:40,620 --> 00:00:46,230 And even if there are some things that are not pretty much the same, you can keep some columns coming 12 00:00:46,380 --> 00:00:49,480 by, adding something to the to this operation. 13 00:00:49,500 --> 00:00:51,780 So we are going to see how it works. 14 00:00:51,990 --> 00:00:53,640 A bit more in depth right now. 15 00:00:54,060 --> 00:00:54,400 All right. 16 00:00:55,230 --> 00:01:02,040 So to be able to make everything to to run it pretty much well, to to understand how this works, what 17 00:01:02,050 --> 00:01:04,100 will do is pretty simple. 18 00:01:04,560 --> 00:01:07,230 We are going to create a data frame. 19 00:01:07,320 --> 00:01:08,220 So pretty simple. 20 00:01:08,220 --> 00:01:11,100 We are going to do what we have learned to in the past two classes. 21 00:01:11,490 --> 00:01:15,150 So first of all, we are going to import our pandas. 22 00:01:15,460 --> 00:01:20,100 So basically here we go as speedy. 23 00:01:20,970 --> 00:01:22,440 And from now on, what will do? 24 00:01:22,500 --> 00:01:26,910 We will create two databases for two basic databases. 25 00:01:27,750 --> 00:01:29,210 Let's say it's going to be food. 26 00:01:29,220 --> 00:01:31,930 So basically we'll have the number of the food, the name of the food. 27 00:01:31,950 --> 00:01:35,100 And finally, let's say the rate or the price of the food. 28 00:01:36,480 --> 00:01:38,670 So let's say we'll have here database. 29 00:01:38,670 --> 00:01:40,110 That will be food one. 30 00:01:42,530 --> 00:01:49,220 And from this moment, we are going to create or thereabouts, so what we'll have at first is pretty 31 00:01:49,220 --> 00:01:49,520 simple. 32 00:01:49,530 --> 00:01:50,650 We'll have the number of the food. 33 00:01:50,660 --> 00:01:53,690 So basically you can just give a number to your food. 34 00:01:54,380 --> 00:02:00,230 And in this case, the number will be from one to five since we are working with food. 35 00:02:00,260 --> 00:02:02,960 So one, two, three, four and five. 36 00:02:03,710 --> 00:02:04,100 All right. 37 00:02:04,760 --> 00:02:07,850 Then the next thing that we will have will be the name of the food. 38 00:02:07,880 --> 00:02:10,330 So basically here will give a name to our food. 39 00:02:10,730 --> 00:02:16,380 So let's call it name and let's do the exact same thing. 40 00:02:16,790 --> 00:02:20,210 So let's say we'll have apples. 41 00:02:23,790 --> 00:02:25,140 Who have on us, 42 00:02:28,890 --> 00:02:29,700 who have. 43 00:02:30,990 --> 00:02:36,330 I don't know, we can have pizza or anything that you want, you can just write down letters because 44 00:02:36,330 --> 00:02:39,370 it's just for the purpose of understanding how this works. 45 00:02:39,370 --> 00:02:42,240 So let's say apple, bananas, chips, 46 00:02:46,620 --> 00:02:47,400 popcorn, 47 00:02:52,350 --> 00:02:57,730 and let's say, I don't know, beans for pizza. 48 00:02:57,770 --> 00:02:59,630 Pizza is better here. 49 00:02:59,970 --> 00:03:00,270 All right. 50 00:03:00,270 --> 00:03:03,670 So we have our five foods, and the last thing will be price. 51 00:03:03,690 --> 00:03:10,440 So basically, we'll have a variable that will be price to have a list of all the prices. 52 00:03:11,310 --> 00:03:11,960 So here we go. 53 00:03:11,960 --> 00:03:14,160 We have, let's say, two dollars. 54 00:03:15,090 --> 00:03:17,280 Three dollars, four dollars. 55 00:03:18,570 --> 00:03:21,180 Eight dollars and six dollars. 56 00:03:21,210 --> 00:03:26,800 All right, so we have our first database right here, so basically our first dictionary or list of 57 00:03:26,820 --> 00:03:30,040 databases that we will use to create our database. 58 00:03:30,450 --> 00:03:33,800 Then next thing will create a second one a bit lower. 59 00:03:33,840 --> 00:03:36,840 So we have found one and the exact same thing. 60 00:03:36,850 --> 00:03:40,040 So we'll create another one that will be called food number two. 61 00:03:40,350 --> 00:03:45,480 And what what is going to be very interesting is that will keep everything the same. 62 00:03:45,900 --> 00:03:50,730 So to understand how it works and emerging, we are going to keep everything the same. 63 00:03:51,210 --> 00:03:55,050 And what we'll do right now, we will create data frames. 64 00:03:55,330 --> 00:03:57,530 So basically a little right here. 65 00:04:00,030 --> 00:04:06,380 So we'll have our table one or you can call it food one, table one, how you want it. 66 00:04:06,990 --> 00:04:10,260 And from this moment, we'll create or the so how exactly we create are the different. 67 00:04:10,260 --> 00:04:13,640 Like always we're going to use pendas pandas to create or the difference. 68 00:04:13,750 --> 00:04:17,160 We will use the extension that you guys can see right here. 69 00:04:17,490 --> 00:04:22,200 So that data frame here, you can find it right there. 70 00:04:23,190 --> 00:04:30,780 And from this moment, we are going to use food one, so food one for our benefit and we'll do the exact 71 00:04:30,780 --> 00:04:33,330 same thing for our table number two. 72 00:04:36,440 --> 00:04:36,920 Here we go. 73 00:04:39,510 --> 00:04:42,800 So don't forget, just change the name when you copy and paste everything. 74 00:04:45,350 --> 00:04:50,730 So right now what we have, we have our list of everything that we are going to use every dictionary. 75 00:04:50,750 --> 00:04:54,690 So for food one and food number two, it should be pretty much the same thing. 76 00:04:55,160 --> 00:04:59,540 So what I want to do right now, so we have our friends that are created right here so they can see 77 00:04:59,540 --> 00:05:06,200 table one will be the data from a food one and the table two will be the delivery of your food number 78 00:05:06,200 --> 00:05:06,400 two. 79 00:05:06,410 --> 00:05:07,920 So very important, number two as well. 80 00:05:08,750 --> 00:05:12,930 And from this moment, we want to fusun everything together or merge everything together. 81 00:05:13,250 --> 00:05:17,540 So basically what we'll do, we will create travel that will be named Fusun. 82 00:05:19,180 --> 00:05:20,630 So we'll call it Fusion. 83 00:05:20,930 --> 00:05:23,460 And here we are going to merge everything together. 84 00:05:23,750 --> 00:05:29,090 So basically, we are going to write down once a year and we are going to use our PDA extension to that 85 00:05:29,090 --> 00:05:30,230 refers to pendas. 86 00:05:30,650 --> 00:05:33,720 And here we'll use the formula merge. 87 00:05:33,740 --> 00:05:38,160 So basically the function merge to merge table one into two together. 88 00:05:38,330 --> 00:05:42,560 So table one as well as table two together. 89 00:05:44,530 --> 00:05:46,210 So right now here, what we done. 90 00:05:46,280 --> 00:05:47,510 What have we done? 91 00:05:47,620 --> 00:05:48,720 It's pretty simple here. 92 00:05:48,730 --> 00:05:53,200 We have merged the two tables together, so this is the formula to merge the two tables together. 93 00:05:53,290 --> 00:05:54,640 So as you can see, it's pretty simple. 94 00:05:55,030 --> 00:05:58,870 And we want to do right now is simply print the variable fusion. 95 00:06:01,350 --> 00:06:02,960 You're going to print fusion. 96 00:06:05,040 --> 00:06:05,700 If we run the. 97 00:06:07,190 --> 00:06:12,470 As you can see what happened, it simply printed everything together, so basically you have merged 98 00:06:12,500 --> 00:06:15,280 the two the two databases together. 99 00:06:15,530 --> 00:06:23,300 So let's say, for example, right now, instead of right here, we write down corn and we run once 100 00:06:23,300 --> 00:06:24,020 again are up. 101 00:06:24,200 --> 00:06:28,580 What's going to happen is that the apple will disappear because it's not the same thing. 102 00:06:29,420 --> 00:06:34,390 So what we'll do, it will merge the two the two databases together. 103 00:06:34,640 --> 00:06:40,070 But if it's not the same thing, well, it's just not going to merge it and it's not going to appear 104 00:06:40,070 --> 00:06:40,790 right here. 105 00:06:40,820 --> 00:06:42,680 So basically, it will just merge everything. 106 00:06:42,680 --> 00:06:49,910 That is the same in the two columns right here in the two databases that are being number one in the 107 00:06:49,910 --> 00:06:50,400 database. 108 00:06:50,440 --> 00:06:54,920 Number two, right now, let's say that you guys want to keep some comments coming and basically make 109 00:06:54,920 --> 00:06:58,910 it work, even if here we have corn and here we have apple. 110 00:06:59,510 --> 00:07:02,180 So basically, let's say here we have corn, here we have apple. 111 00:07:02,180 --> 00:07:04,490 The price of the corn is not two dollars. 112 00:07:04,490 --> 00:07:05,750 It's going to be I don't know. 113 00:07:07,660 --> 00:07:14,590 Eight dollars, for example, in here, we don't have chips, we have, let's say, beans. 114 00:07:16,420 --> 00:07:22,150 All right, so let's say we want to keep the column a name so common. 115 00:07:22,480 --> 00:07:30,130 What we'll do, it's pretty simple right here after our table to we will simply add a comma and write 116 00:07:30,130 --> 00:07:31,900 down on so on. 117 00:07:33,180 --> 00:07:35,130 Equal to what exactly? 118 00:07:35,160 --> 00:07:39,930 Want to keep coming, so we want to keep the names coming, so basically we'll just write down a name 119 00:07:40,290 --> 00:07:42,150 because we want to keep the name coming. 120 00:07:42,630 --> 00:07:47,050 And if we on the up, as you can see what's going to happen, we'll have our names. 121 00:07:47,050 --> 00:07:51,550 So right here, we'll have our Barona and we'll have everything that one. 122 00:07:51,570 --> 00:07:54,120 So basically, we keep the name coming right here. 123 00:07:59,930 --> 00:08:04,520 If you want to do the exact same thing for numbers, we can do it so we can just put everything we can 124 00:08:04,520 --> 00:08:09,380 just take it and write down the numbers and we run everything together. 125 00:08:09,380 --> 00:08:11,500 And as you can see, it's going to do the exact same thing. 126 00:08:11,750 --> 00:08:13,920 So the numbers will be coming in this case. 127 00:08:13,920 --> 00:08:19,250 So you can see the court appears and we have our corn for eight dollars and we have our apple for two 128 00:08:19,250 --> 00:08:20,320 dollars as well. 129 00:08:21,170 --> 00:08:23,580 So you can see it's pretty simple to understand. 130 00:08:23,600 --> 00:08:27,530 So basically, the first thing that you guys want to do to be able to make sure well, to be able to 131 00:08:27,530 --> 00:08:31,010 measure, not function, is to be able to measure database's. 132 00:08:31,020 --> 00:08:33,860 It's pretty simple what you want to do at first. 133 00:08:33,860 --> 00:08:35,510 You want to create your database. 134 00:08:35,550 --> 00:08:39,410 So basically here you will have your list that will be used for databases. 135 00:08:40,130 --> 00:08:45,860 Then you simply put those you create dereference with those data bases that you have. 136 00:08:45,860 --> 00:08:51,860 Well, with your list, you put all your lists in form of data frames right here with this function 137 00:08:51,860 --> 00:08:56,280 right there, and then you simply merge everything with the function right here. 138 00:08:57,200 --> 00:08:59,840 So I hope you guys understood this operation. 139 00:08:59,850 --> 00:09:01,250 So it's pretty simple what it does. 140 00:09:01,250 --> 00:09:05,060 It simply put together two databases that are not together. 141 00:09:05,330 --> 00:09:10,910 And when I see together, it's it will simply put together everything that is the same in the two databases. 142 00:09:11,060 --> 00:09:15,230 So everything that is not the same will just not be put it inside of this database. 143 00:09:15,620 --> 00:09:22,060 But it's possible to keep some Collins common as well with the UN function inside of our merge function. 144 00:09:22,550 --> 00:09:25,760 So that's a first class guys, all in our next class.