Hello, everyone, in this session, we will discuss about sorting and merging of data frames, so the
first thing which we will discuss is sorting data by one or more columns in ascending or descending
order.
Then we will discuss how we can combine data frames vertically or horizontally.
Then we will learn about merging them, using keys left, right, in and out the joint.
OK, so let's begin with it.
So initially we will import Fondas and the number of.
After importing these, I will be creating a new data frame, so this data frame is created from values.
It has a shape of 20 cross food and it has values from two to eight.
And the column names are A, B, C and the.
This is the data frame which has been created, this data frame has 20 rows.
And four columns now we will try to sort these using column E to sort these using column E, we will
use D.F. dot sort values.
So our values is a function which is used to sort of values in a Dufrene and we give the column by which
we want to sort this out as the initial, the first parameter and the next barometer is in place.
So in place operator here is means that if we give in place equal to do, then it will change the data
frame itself.
So if I change this.
Then it will modify the data frame itself.
So if I print the data frame, the data frame will be sorted with respect to it.
Now, another thing, what I can do is I could have not given in basically due to if I did not give
in physical truth, then the changes will not take effect in the device.
So in that case, if I am not giving in basically true, then I would have to write it in a form like
D.F. is equal to the sort.
And without this.
So if I am not writing in, please, then I have to give this particular format to make it effective,
otherwise I can simply the idea of sort values, I'm simply saying, please, equal to two.
Now, this is for sorting one column if you want to sort this column in descending order.
And then what we can do is there is of the bottom of it, just ascending.
So if by default ascending is said to be true.
But in case we want to sorted in descending order, then we will have to write a sending people to Fuld's.
So if you will put this ascending hold for us, then we saw this in descending order.
So you can see that the column is decreasing.
Now on a IS.
We can also sort the values on the basis of multiple columns.
So when we are sorting columns on the basis of multiple columns, in that case we will have to provide
the argument of column which was given here.
Initially we were giving just one column name here, but now we will have to give a list of column names.
So we will give a list of column names.
And based on the list of column names, we can give ascending values again in form of list.
So you can see the difference here.
Initially we were giving just.
A Anderson default falls now we are giving with the values in a list for them, so once we do this,
the values are sorted accordingly.
So it has been sorted based on that.
And on top of that, the values are sorted on the basis of the and then the values have been sorted
on the basis of C, B in ascending order, the C in descending order of.
Next thing, what we can do as of now, this source, the data by Colombe in ascending order but sorting
by golems happens in descending order.
So initially it was sort all the values of B in ascending order and then the values of B, that here
we have three values as two.
Right.
So these values will be sorted for the on the basis of C, so it will force or B and after sorting B,
the values corresponding to B will be sorted and these values will be sorted accordingly.
Now we'll look at how we can combine different data set, so here I'm creating a data frame V1 and this
data frame consists of volumes of letters and numbers.
So there are letters and the numbers, one and two.
And I've given the column names also.
Similarly, I have created another data frame with value.
See these three four.
Gandal So I just run this now.
So these are the values which has been created, these are the things which have been created now,
as you always remember, those are equivalent to Zettl and columns are always equivalent to one.
So we always did this.
We just remembered using this rose.
Former columns, and this is written in a way zero one one, so whenever I see Zettl, it means we are
working with rules and whenever I see one, it means we are working with columns.
So here what we are doing is we are concatenating, we are combining, we are just fisting them together.
So we are basting our data from one data frame two together and we are basting them on the basis of
access to this means that we are facing them always.
So that means the rules of the event.
One will be present at the top and after that the rules of data frame will be present.
Now, whenever the values for the data frame one are missing.
So as you see in data frame one, we do not have the column animals present.
So what happens is.
Whatever the value is not present, it gives not a number there.
So here we have concatenated these on the basis of X is zero.
OK, so in case more columns were present in data frame to all those columns will be added here and
the values will be given as not a number.
Now, similarly, if we are doing the same thing now, if you one more thing to notice here is the indexes
have we have not been modified.
So in my first data frame, the index was zero one.
Here again, the index was zero one.
So while sticking them together, it has actually retained the original indexing.
So if you want to make the indexing again, correct the index, then what we can do is we can simply
ignore index and mean said that through.
So when we said this thing to.
What happens is.
Let me just run this again.
So when we put this concatenated this, so what happens is it will simply retain the create a new index
for this so it will change the indexes from zero one zero one two zero one, two, three.
Now, another thing which we can try here is I'm creating a new data frame, data frame three.
Now, this data frame consists of a column Unimin and another column name, and it has three rows of
data, which is board volume monkies, your Staiger John.
So these are the values which are present in this particular detainee.
So we are trying to concatenate these by axis one.
Now, what this means is that we will have this particular data frame.
We will have the data frame to.
This particular data frame, this is the data pointing to a different data frame to heal forced.
So this is day two, sorry.
This is the data frame do this is to be the frame to be, and what we're trying to do is we are going
to be needing data from two would be to frame three.
Now, what happens is the full data frame has two rules and three columns.
The second data frame has three rows and two columns.
So as a result, then we get five columns.
That is letter number, animal animal.
I mean, this is what we get by concatenate them with access one, which is column based concatenation.
And what we get is we again get because the rule number is two here and three here.
So it creates three rules.
And wherever we don't have values from this particular data frame, it makes them as not a number.
So it improves the value as not a number.
And once we have done that, once we have done all the sorting, once we have done the combination,
whatever, merging, whatever we are trying to do, what we can do is we can then improve the values,
how we view the values.
We see that little.
But for now, just try to understand that these values will get generated and it will not have an empty
value.
It will have more than that.
Now, the next thing what we can try is.
So we Maskin got donated by Accies one, similarly, we are trying to concatenated Dufrene one, we
did frame three.
So what it does is it again creates the values, not no matter what.
The values were not present.
Now, let us discuss how we can move to different data frames, so here I am creating other data from
the data frame.
One contains one column customer data, which contains volumes one to five, then out of the column
contains the product.
Then that is another data frame which contains the customer I.D..
And along with the customer itis.
It contains the state now.
Now, let me run this.
So this is the data frame when this is the data frame, too, so here we have customarily and you can
see that for the similarity, one, two, three, four, five.
These are unique values.
And we have video footage which are kind of repeating.
Then here we have another the customer I.D., which are different from the customer I.D., which are
present in this data.
Name one.
So we are next trying to merge these data frames, so why we are merging the data frames, what we are
doing is we are merging the data from one with data frame two.
And we are merging it on customer already, so we are seeing feed thought much and we say if one the
to, then we give the key on which we want to merge these ideas and how we want to merge this.
So this is the type of joint which we are trying to have.
So this is in our joint.
So when we say in our joint, that means that we want to keep only the rules which are common between
this Dufrene one and the same two.
And we want to keep the commonness on the basis of the customer.
So we have customer varieties.
One, two, three, four, five year and we have three, four, five, six, seven.
So the common customer IDs are three, four and five.
So we are expecting to have only three rules in this particular little thing.
So while I run this, I get three rules from the state of Maine.
Now, the next is we want to join on customer idea again, but we are wanting to join it on the outer
join.
So what our vision gives us, it gives us rules from all of the things, all the rules from the date
of names.
So we will get.
Customer added one, two, seven, all of these customer IDs would be present.
So once we've done this, we get customer I.D. one to seven and all the details in front of them now
because customer IDs, six and seven were missing in the frame one.
So the product values have been imputed as not the number here.
And because the customer IDs, one and two are missing in between two.
So that is the reason why they see this coming as not the number here.
Now, next is customarily merging on customarily an.
I joined this group, so I left join will basically give us.
These are the two data frames which we have and we are keeping data from one on the left hand side.
So this way we will get the columns which are from the.
We will get the rules which are present in the next day, the family, so the rules are one to five.
So when we are doing left joined, we are getting close one to five and the details which are missing
on the right side, thebus that has been imputed, that has been created.
Now, similarly, when we have this right joint, so the columns of the rules are picked from the right
inside the ring, which is date of name to which has rules three to seven.
So all of these are present.
And the product, the product, the definition does not have the rule six and seven.
So that is why the number has been created here.
Now, a similar kind of things you can try to own here.
We have more combinations so you can see we have the frame 20 frame three in the frame four.
So now here what we have is in the frame three, we have values repeated.
So the date of the T has to twice.
And it has a lot on unbottled.
While the Dufrene Ford has won the bidding twice and it doesn't have an number here.
So what we do with.
So now when we merge these different three days of rainfall, one customer arrive and have inner join,
then what we get as a result is because the Zatarain three ended up rainfall has customer already one.
For.
In phone, so we get one, two and four, and the repetitions with the president are coming as it is
so because the best humanity has repetition in the deafening for so it is taking what the values and
values on both of these.
And because the cost when I was presenting the different three twice.
So it is generating values on top of these and facing the values accordingly.
Similarly, all the violence will be imputed when we are generating a left join order, I join.
So please try all these scenarios.
Thank you.