WEBVTT

00:00.510 --> 00:04.220
In this video we learn how to select columns from a data frame.

00:04.230 --> 00:12.180
But before we have to import Parnassus PD as always then we import our Titanic data frame and assign

00:12.180 --> 00:17.210
the variable Titanic and we will have a look here at the first five throws.

00:17.220 --> 00:18.710
We already know this.

00:18.960 --> 00:22.820
And then let's assume that we are only interested in the H column.

00:22.830 --> 00:29.850
So we want to analyze them the age of all passengers that are aboard the Titanic and we can do this

00:29.850 --> 00:32.760
by riding Titanic here.

00:32.760 --> 00:34.740
So that's all a data frame.

00:34.740 --> 00:41.130
And then we open the scrap racket and then we pass the label off our column that we want to select.

00:41.130 --> 00:49.330
So in this example it's some H and we have to posit in quotation marks.

00:49.390 --> 00:56.200
So now here we select the H column let's run the sail here and you can see we got all values within

00:56.200 --> 01:03.640
the H column at the same order as in our data frame and still on the left here we have the index labels

01:03.700 --> 01:05.130
off our data frame.

01:05.290 --> 01:14.350
So at index position 0 or label 0 we have 22 as an H and journal label the one we have from a peasant

01:14.350 --> 01:14.990
service.

01:15.070 --> 01:17.410
Thirty eight years old and so on

01:21.980 --> 01:28.730
and we can also check that the data type here off our column so let's copy and paste and then let's

01:28.730 --> 01:30.140
check in the data type

01:34.680 --> 01:41.930
and here we get a panda serious so the pen that serious is also that data Tidewater class within the

01:41.930 --> 01:49.130
panda's library and it's one dimensional label array so you can see here we have as an atlas or name

01:49.220 --> 01:52.790
one dimensional name pi array one sequence of values.

01:52.790 --> 02:00.440
So we have one dimension here and so here on the left we have a label and as I said before so the serious

02:00.440 --> 02:07.740
is also a class all data type which has specific attributes and methods which we will learn later and

02:07.740 --> 02:10.980
most of the methods and attributes are quite similar to a data frame.

02:10.980 --> 02:17.760
So there are some methods some attributes that we can only apply with a pen that serious and the other

02:17.760 --> 02:23.790
way around there are some methods some attributes that can only apply to Panda's data frames.

02:23.790 --> 02:30.780
So now what if we want to select a column but we want to still have it as a data frame so let's paste

02:30.780 --> 02:32.280
again here our column.

02:32.280 --> 02:39.330
And if you want to have a data frame instead of a serious we can pass inside this back brackets our

02:39.570 --> 02:44.470
H column with another aspect bracket here.

02:44.700 --> 02:50.850
So we have doubled our bracket and the fear around this year and we can also see from the layout that

02:50.970 --> 03:05.150
this could be a data frame and that's copy and paste and let's check in the type here.

03:05.280 --> 03:10.700
So in this manner we are still a data frame by having two spat brackets here and depending on what you

03:10.700 --> 03:16.360
want to do with them the column you can either selected as a pen that serious or as a data frame.

03:17.540 --> 03:18.010
All right.

03:18.020 --> 03:18.710
So now what.

03:18.710 --> 03:23.000
If you want to select the two columns.

03:23.000 --> 03:33.590
So let's assume you want to have the edge column and the sex column somebody tried to do this by passing

03:33.590 --> 03:39.790
age and sex in within the span bracket and you would get an error message.

03:41.090 --> 03:48.470
So something is wrong here and the solution is that if you want to select many columns we have to pass

03:48.560 --> 03:52.600
them as a list into our spam brackets.

03:52.970 --> 04:01.250
So we have to pass them the list with age and sex to our staff brackets and let's see what we got here.

04:02.970 --> 04:08.850
Now we got here a data frame with them the age column and the sex column and still on the left side

04:09.390 --> 04:17.870
we have the row labels and we can also rearrange here the order off the column so let's copy here and

04:17.870 --> 04:24.260
paste again can rearrange them the order of the columns the fear change and the sequence here and our

04:24.260 --> 04:25.070
list.

04:25.190 --> 04:31.080
So let's say we want to hear the sex column before the age column.

04:31.760 --> 04:32.420
We can do this.

04:32.450 --> 04:37.930
So now we have them first to the sex column and the column compared to here

04:42.080 --> 04:46.100
and of course we can also select multiple columns.

04:46.360 --> 04:52.000
So let's copy and paste and we can also include here within our list.

04:52.100 --> 05:01.880
The fact column now we get a pen this data frame with three columns six H and fair and therefore the

05:01.880 --> 05:11.750
same order and the original data frame so let's check again the original data frame the first rows and

05:11.750 --> 05:12.720
then we can see it.

05:12.740 --> 05:21.050
So the first row we have a male which is 22 years old and paid a fare of seven point two five pound

05:21.080 --> 05:24.780
or dollar and the second row here.

05:24.820 --> 05:31.690
We have a female thirty eight years old and the female paid seventy one point two dollars or pounds

05:33.250 --> 05:36.620
so you can see here the order of our rose and then our slice.

05:36.630 --> 05:44.010
Yes exactly the same as in the original data frame and that's a second way to select one column.

05:44.040 --> 05:52.680
So either we do this by passing our column within the span brackets or we can just use the pandas attribute

05:52.710 --> 05:55.950
dot and then the name or label of the column.

05:55.950 --> 06:03.360
So for example h here so we have h as the column label and automatically in our data frame this and

06:03.360 --> 06:08.350
the attribute top eight so let's see what we get here.

06:09.190 --> 06:09.320
Yeah.

06:09.350 --> 06:13.040
And we actually got the same pattern as serious with our H column.

06:13.040 --> 06:18.680
So here we have all the values of our each column and also here on the left side um the labels

06:22.300 --> 06:29.200
and last but not least we can check if both alternatives are actually the same

06:32.070 --> 06:39.120
so we can check if I'm here I will see areas that we created within the attribute H equals

06:41.690 --> 06:49.850
and then we can pass on the second alternative so titanic and passing H and we get a true here.

06:49.880 --> 06:56.810
So the method equal checks whether the pen does serious Titanic that HCR actually the same s and the

06:56.810 --> 07:02.420
pen as serious and that we created here was pap records and it's actually a matter of taste if you select

07:02.420 --> 07:09.420
a column with them the attribute or the spell brackets and later we will learn that there are some minor

07:09.420 --> 07:17.700
differences however for just the selecting a column and both works the same way and in my opinion the

07:17.910 --> 07:20.630
attributes and sometimes a bit more comfortable.

07:20.640 --> 07:30.550
So if fewer type a titanic thought and if you want to select the let's say the impact column we press

07:30.580 --> 07:38.110
M and then we benefit from the tab completion function so now if you press the the tab key then Python

07:38.140 --> 07:44.560
automatically checks which attributes are available and uh see some that there's some the impact column

07:45.400 --> 07:49.900
and then we have here the impact column as a panacea is.

07:50.680 --> 07:54.420
So this is quite comfortable actually.

07:54.460 --> 07:54.760
All right.

07:54.760 --> 07:59.460
So now we have finished the session and in the next session we learn how to select growth.

07:59.470 --> 08:00.660
Hope to see you there by.
