WEBVTT

00:01.110 --> 00:05.530
In this video you will learn how to change one or many elements in a data frame.

00:05.580 --> 00:08.320
And this is actually pretty straightforward.

00:08.340 --> 00:12.820
So first of all you have to select the elements you want to change with Loke.

00:12.930 --> 00:19.020
I log our filtering techniques and then you have to set a new value on new values.

00:19.050 --> 00:25.250
So first of all we import pen us and also here we are working with the Titanic dataset.

00:25.260 --> 00:29.920
Now let's have a look at the female passenger with the index label 1.

00:30.240 --> 00:35.770
She is the 38 year old and it assumed that her correct age was 40.

00:35.940 --> 00:42.960
Then we can simply change this element here in the data frame by first before selecting the element

00:43.380 --> 00:51.060
and we can do the same with the lock operator so we select the passenger within next label 1 and tier

00:51.090 --> 00:56.690
the element and the H column 38 and then we actually set or we determine a new value.

00:56.700 --> 00:58.740
And in this case c a 40.

00:58.830 --> 01:03.440
So let's do this here and let's have a look here at our data frame.

01:03.660 --> 01:11.310
And here we have 40 and the same we can do actually also with the ILO operator and position based indexing

01:11.820 --> 01:18.240
and we select the passenger at the next position one and we want to change the element in the column

01:18.240 --> 01:20.100
with the next position 3.

01:20.460 --> 01:32.320
So that's the H column and we set to the value of 41 then we fear 41 and we can also change or manipulate

01:32.440 --> 01:33.810
many elements.

01:33.880 --> 01:42.070
So let's assume that the passengers with the index labels are 1 2 and 3 actually 42 years old.

01:42.070 --> 01:49.570
Then we can do this here with the label based indexing so we select these three elements here and we

01:49.570 --> 01:51.700
set the new value forty two.

01:52.300 --> 01:53.610
So let's have a look here.

01:54.990 --> 01:57.450
And here we have a three times forty two.

01:58.060 --> 02:01.740
And let's assume that the peasants with the next label one is forty two.

02:01.980 --> 02:07.260
Then the next passengers 43 and the next one forty four.

02:07.260 --> 02:13.120
Then we can also simply do this and instead of passing here only one value forty two we can pass you

02:13.200 --> 02:17.810
a list with three elements 42 43 and 44.

02:17.820 --> 02:20.340
So that's no problem at all here.

02:20.550 --> 02:22.890
And let's go to the next example.

02:22.920 --> 02:25.600
So he and the H column we have the H.

02:25.620 --> 02:26.560
And yes.

02:26.730 --> 02:34.770
And let's assume we want to convert the H and yes to the H and month then we can simply do this by selecting

02:34.770 --> 02:41.820
here the H column so we select all rows and the H column and then we multiply each and every element

02:41.820 --> 02:49.710
in the H column with 12 so that that's the new values and then we need to override the H column and

02:49.800 --> 02:55.110
therefore we also have select the H column and we set here the new value.

02:55.110 --> 02:56.070
So let's have a look

02:58.820 --> 03:02.370
and here we have now the H month and set off years.

03:02.540 --> 03:08.090
And of course we can also convert this back two years by dividing each and every element he and the

03:08.090 --> 03:17.790
H column by 12 and then we assign the new values here for the H column and again here we have for the

03:17.790 --> 03:18.180
H.

03:18.180 --> 03:25.510
And yes and now let's go to a filtering and let's assume that we want to set for all babies that are

03:25.650 --> 03:28.580
less than 1 year old the value of 1.

03:28.650 --> 03:37.470
So first of all we select all rows all passengers where the H S below 1 and we actually select the index

03:37.470 --> 03:45.670
labels and we start the index labels of the babies and the variable index babies and let's also slice

03:45.670 --> 03:48.820
for these rows of these passengers here.

03:48.940 --> 03:53.250
So that's the baby passengers with an H below 1.

03:53.530 --> 03:57.720
And now for all of these passengers we want to set the new age of 1.

03:57.730 --> 04:05.740
So we want to around up actually and we can do this uh by selecting the H column for passengers where

04:05.740 --> 04:07.440
the H is below 1.

04:07.450 --> 04:12.370
So instead of passing the Titanic that s a smaller one we could also pass here.

04:12.490 --> 04:13.930
Index babies.

04:14.080 --> 04:16.490
But here that's a more explicit.

04:16.490 --> 04:23.210
And then we set the new value 1 and let's again select all babies here.

04:23.710 --> 04:31.840
And here we have successfully changed the age of all babies to 1 so these are a few examples how to

04:31.840 --> 04:35.200
change one or many elements in the data frame.

04:35.200 --> 04:40.450
And there are many more ways to do it but for the time being we are finished here and I hope to see

04:40.450 --> 04:41.980
also in the next video by.
