WEBVTT

00:01.110 --> 00:06.460
In this video we learn how to change a single column labels and a single index labels in a pen.

00:06.470 --> 00:08.160
That's data frame.

00:08.160 --> 00:14.160
And so far we only learned how to change and replace a complete row or column index.

00:14.160 --> 00:20.640
And there are many cases and rewrote but we only want to change one or two entries in an index object

00:21.210 --> 00:28.470
so let's import pandas here and we import our Summer Olympic Games medal data set and we said to the

00:28.560 --> 00:30.480
athlete column to the index

00:33.680 --> 00:36.150
and then we can select our index object here.

00:37.040 --> 00:41.840
So here we have our labels of our row index and we can select a single entry.

00:42.380 --> 00:52.950
So for example the first element in exposition 0 here it's off the tiles and let's assume now we are

00:52.950 --> 00:56.700
not happy with the spelling of for the tiles.

00:56.700 --> 01:05.910
So we think that there must be a Y instead of a J and we can try to set our new value here and we get

01:05.910 --> 01:13.500
here an error message because an index object M is immutable the however there is a way to do this or

01:13.530 --> 01:21.720
to change a single label or entry with the rename method so let's have a look at the renamed method

01:21.750 --> 01:30.490
and press shift tab and in the rename method we have to pass a map bar and in the map we have to define

01:30.490 --> 01:34.930
the old label that we want to rename and we have to define the new label.

01:35.230 --> 01:41.800
And other methods would be actually a dictionary where on the left side is the key we have to define

01:41.970 --> 01:44.610
the oth label that we want to replace.

01:44.800 --> 01:52.870
And on the right side as well you of our dictionary we have to define the new value of the new label

01:53.020 --> 01:59.610
that replaces and the old label and that's another parameter called Xs.

01:59.610 --> 02:03.730
Where it we have to define which X is them on a map.

02:03.750 --> 02:04.560
Also target

02:07.960 --> 02:14.320
so in other words we have to define in which X is spend US should change here for the tiles.

02:14.350 --> 02:21.670
And here in our example we have to define um the row axis and either we can pass a zero.

02:22.500 --> 02:24.540
Let's check here.

02:24.940 --> 02:32.500
Now we have our new spelling with the Y all we can say in quotation marks uh index.

02:32.590 --> 02:36.770
So both alternatives are possible here and also here.

02:36.790 --> 02:46.060
We get off the tiles and y and last but not least the less and the in-place perimeter which we have

02:46.060 --> 02:50.950
to set to true if we want to change our data frame and set up the new value here.

02:53.050 --> 02:56.060
So now let's check again our data frame.

02:56.530 --> 02:59.800
And here we can see that we have changed our label three tiles.

02:59.860 --> 03:02.530
So here we have now a Y.

03:02.830 --> 03:05.790
And we can also do the same for a column label.

03:05.800 --> 03:12.970
So for example we want to change the gender label to sex and we want to change the city label to host

03:12.970 --> 03:20.520
city so we can change more than only one label so we can change many labels here and we can create a

03:20.910 --> 03:24.120
map dictionary with many a key value Paris.

03:24.120 --> 03:32.440
So here in this example to key value pairs so we have here our dictionary and on the left side is the

03:32.440 --> 03:40.200
old label that we want to change gender and as a value the new labor and then be separated with a comma.

03:40.230 --> 03:44.360
And then on the left side that's another key of our dictionary city.

03:44.370 --> 03:47.020
So this is the label we want to change.

03:47.030 --> 03:54.260
And on the right side as the value of our dictionary f our new label host city and again we have to

03:54.260 --> 03:56.110
define the axis.

03:56.450 --> 04:00.020
And in this case it is the column axis.

04:00.050 --> 04:00.740
So one

04:03.630 --> 04:08.000
so we can see where your host city and sex are not gender.

04:08.010 --> 04:12.870
And instead of passing one to the parameter axis we can also pass columns

04:17.100 --> 04:19.060
so we if you have a city and sex.

04:19.080 --> 04:23.930
And again we have to separate the in-place parameter to true.

04:23.970 --> 04:32.340
If you want to change our data frame and let's say again all that a frame and now we can see here.

04:32.370 --> 04:39.420
So we changed our label for the tiles our index label and we changed our column labels host city and

04:39.420 --> 04:42.610
sex.

04:42.890 --> 04:43.280
All right.

04:43.280 --> 04:47.360
So now this is it for the time being and hope to see you in the next session by.
