1
00:00:00,670 --> 00:00:05,270
Later on you learn how to extract portions of a data frame.

2
00:00:05,370 --> 00:00:09,840
Let's say you want these three values here.

3
00:00:09,840 --> 00:00:12,540
These three and these three in here.

4
00:00:12,780 --> 00:00:16,610
So that's portion or maybe you just want one single value.

5
00:00:16,620 --> 00:00:21,930
In that case you need to find a way to refer to that single value by coordinates.

6
00:00:22,050 --> 00:00:27,990
When I say my coordinates I mean like by column name.

7
00:00:28,000 --> 00:00:35,070
So you'd be referring to name because you want this value of this column and also you'd have

8
00:00:35,070 --> 00:00:41,190
to refer to the row, and for that we have the index concept.

9
00:00:41,190 --> 00:00:48,180
In this case you see in bold here that the index has been assigned by default by pandas.

10
00:00:48,180 --> 00:00:51,930
So it starts from 0 always, the default index from 0 and so on.

11
00:00:51,930 --> 00:00:58,530
If you want, if you have your own index such as in this case I would like to to assign ID as an index

12
00:00:58,770 --> 00:00:59,390
of these data.

13
00:00:59,400 --> 00:01:08,910
And later on when I show you how to refer to certain values you would be using that ID to refer to

14
00:01:08,910 --> 00:01:10,200
those values.

15
00:01:10,200 --> 00:01:21,030
So how to assign an index a new index to your data? Well, you can do that with df8.set_index.

16
00:01:21,030 --> 00:01:28,920
And then you assign the name of the column that has those values that you want to set as an index.

17
00:01:28,950 --> 00:01:34,750
So ID in that case, in my case and this is what happens.

18
00:01:34,950 --> 00:01:45,300
Now here you have to be very careful because the set index operation is not an in-place operation meaning

19
00:01:45,300 --> 00:01:47,960
that when you apply that method

20
00:01:47,970 --> 00:01:56,050
It produces a new data frame but just on the fly, it doesn't actually modify the existing data frame.

21
00:01:56,100 --> 00:01:59,520
So df8, the object remains the same as you see in here.

22
00:02:02,630 --> 00:02:10,100
Therefore if you want to have the changes you may want to create another variable where to store the new

23
00:02:12,650 --> 00:02:13,250
data frame.

24
00:02:13,580 --> 00:02:25,430
So this is actually equal to a new data frame with that index set in, and df9 now will be a permanent

25
00:02:25,610 --> 00:02:31,700
object, a permanent data frame with ID s index. There is also another way if you like.

26
00:02:35,890 --> 00:02:41,880
You can still do the same thing and say inplace equals to true.

27
00:02:42,010 --> 00:02:48,610
In this case the df8 is modified permanently as you can see in here.

28
00:02:49,510 --> 00:02:55,990
However here you have to be very very cautious because what's happening here is that at the moment

29
00:02:55,990 --> 00:02:59,720
df8 has as an index column ID.

30
00:02:59,920 --> 00:03:07,630
Now what happens if you set as index the address column instead?

31
00:03:13,400 --> 00:03:21,160
We're talking about df8. The address column is assigned successfully as an index.

32
00:03:21,200 --> 00:03:22,280
That's good.

33
00:03:22,280 --> 00:03:26,660
However if you look for the ID column, it has disappeared.

34
00:03:26,660 --> 00:03:34,790
So what happens is that the set index method it sets a new index, but  the old index is not assigned

35
00:03:34,820 --> 00:03:42,840
as a column so ID is not to reassigned as a column of a data frame, it just drops, it is deleted.

36
00:03:43,130 --> 00:03:45,870
However there is a way to avoid that.

37
00:03:46,100 --> 00:03:54,150
What you can do is let me repeat a similar operation, this time I want to set as ID

38
00:03:54,230 --> 00:04:01,570
the name, inplace equals to true and the existing index is address.

39
00:04:01,700 --> 00:04:02,510
So we are setting

40
00:04:02,510 --> 00:04:08,450
name, the existing address and you have to say drop equals to false.

41
00:04:11,300 --> 00:04:18,450
So what's happened here is that name remained as a column also.

42
00:04:19,140 --> 00:04:23,700
So it's an index but it's also a column, however address was deleted

43
00:04:23,700 --> 00:04:25,110
again as you can see.

44
00:04:25,690 --> 00:04:32,320
So this actually drop equals to false tells Python not to drop as a column the column

45
00:04:32,320 --> 00:04:35,130
that you are setting as a new index.

46
00:04:35,130 --> 00:04:40,590
So please keep that in mind or just use the other method where you create a new variable.

47
00:04:40,590 --> 00:04:42,740
It depends on a scenario but yeah.

48
00:04:42,780 --> 00:04:44,400
Please keep those things in mind!

