[MUSIC] Hi in this video clip let me explain data frame slicing. For data frame slicing you can either use label index or position index. In case of label index slicing, you use loc. If you want to use position index based to slicing, in that case you use iloc. Sometimes you want to pinpoint specific data point by specifying column name and row name. So you can pinpoint a specific data point by using label index, in that case you use at. If you want to use positional index in pinpointing a specific data point, you use iat. So let me give you an actual example of slicing data from our data frame. We are using season_temp object. This object contains temperature measurement for each season. There are four seasons, but we are slicing only spring temperature and fall temperatures. We take all measurement. So we are not specifying any row indexes, simply, we are stating column names. So by stating column names, we can slice the temperatures. So here spring and fall data are sliced. Another way of slicing columns, in this case we are using loc, in case of loc we are using label index, not position index. So we didn't break it. There is a row, row selection, but we are not giving any index for rows. It means that we are taking all row measurement, right? And comma separating row and column. In column part, there's another bracket within that bracket, spring and winter specified. It means that we are not using rangy slicing. We are specifying columns. So we are choosing specifically spring column and winter column. So let's see what happens. So spring and winter data are sliced. Another way of choosing specific column. If it is just one column, in that case, you can use. If you want to use choose spring column, then you use after the object name, you provide column name. Then you see just spring column data. So first I'm introducing examples of column based slicing. Another column slicing example is provided here. iloc case, the same data frame is used, but at this time we are using iloc, means that we are slicing data based on position index. Again, row index is not specified, we are choosing all row data. And in this case, we are assigning range column indexes from 0 to 2, but the last 2 index is not inclusive. So two columns will be chosen, spring and summer, right? But if you want to choose specific columns, you need to specify column numbers. So in the second line, you are specifying read in brackets, you are specifying the first column and the fourth column, the last column. So at this time, spring and winter, data will be sliced, right? So far I explained column slicing, but now it's time to study row slicing based on range index. Now let's use scores on the bar, ni, it is scores data fame. You are specifying row range from 0 to 2. It means that only two rows will be chosen. If there's only one bracket, it is row index. If there's row index range and comma, then after that you can specify column information, column indexes that you want to slice. But at this time, you are not giving any column index, it means that you are taking all columns, but you are specifying a part of a row. That's why only two rows will be printed. So Math and Econ data is provided, sliced. In the second line, what you see here is that we are using loc tool, loc command. And within that loc, there's double bracket, and we are specifying row names. At this time, we are choosing Math and Econ. For example, if you use Physics, you can change it simply Physics. Then what you see is Maths and Physics information. Again, if you want to add column, after comma, you put column information. But we are simply for crossing on row slicing. Another way of slicing rows, and at this time we are using iloc, we are using positional index from 0 to 3. It means that all three rows will be printed. Which means that the whole data set itself will be printed, right? If you want to reduce, for example, 2, you simply change the row numbers. Then accordingly the data set is sliced. And also by specifying row numbers in iloc, you can change the data set. For example, if it is 2, it is fourth line like Physics, let's execute again the above cell. Then the data set actually looks like this one, Maths, Econ, Physics. We we are using the same data set, but if we specify 2, it means that we are trying to change Physics scores. And we are therefore be placing scores information, we are using dictionary data set. For each dictionary readers, column names, those are keys, and there are matching scores for each key. Then execute this. What you see here is the Physics score is changing based on this one. So using index slicing method, you can also replace data elements within data frames. Now let me give you more examples of slicing based on row indexes. Now it's time we are using the same data sets course on the bar ni, but we are using ranges separator, from Math to Physic. It means that the whole data set will be printed, right? Another case, iloc, at this time we are limiting row numbers and column numbers. So the ending number is 2. So it means that the first row and second row will be chosen, and four columns will be chosen. So if we execute this set again, then we see this, three column, two row indexes. Not 4 columns because the ending number is 3. So 0, 1, 2. First three columns will be sliced as shown here, right? The other case we are using iloc, and we are specifying row numbers. It is not range index, it is specific row indexes chosen and column. In case of column, range index is used. So what you see here is Computer and Food, right? And three persons, first the three persons data is returned. Now, in case of loc, you can use range index, and at this time you are specifying column names. So it is another example of slicing. The next one is similar to the previous one, this one. But at this time, we are not using range indexing. We are choosing rows, specifically to rows, Math and Physics. Then we see this outcome. This outcome is similar to the previous one. But because we chose specifically Math and Physics, that's why Econ data disappeared in this case. Now let me give you a specific choice of element. But before providing that example, let's see first the data set that we are going to use. This is the scores on the bar df, at this time we are trying to pinpoint specific data point. So computer and kwon, this is at. We are using label index that's why we are putting labeled names reading at. So computer, where's computer? Is its a Kwon, is it a Joo? So 100 will be printed. Scores on the bar df, iat, we are using position index. The position number is 1 and 3. Which one is 1? Chemistry is 1, and Kwon is 3, that's why right will be printed. So we ask you again this cell. Then 100 and 90 scores are printed. So iat is for position index, and at is for label index. Here is a review question, true or false. loc is for label-based slicing and iloc for position-based slicing. True or false? It is true, because that's what I just explained.