INDEXING & SLICING DATAFRAMES IN PANDAS - PYTHON PROGRAMMING

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hello friends welcome back to our channel so in this today's session we will discuss about how can we access the rules from the data frame in partners so in the previous session we have discussed about how to create the data frame in pandas and now we will see how to access the elements right so accessing or slicing we can also call this slicing so accessing means we are having a function called head this head function is used to get the first five rows first five rows will be displayed okay and if you give any parameter here the number of rows to be displayed that many number of rows will be displayed for example if you give here as a three the three rows will be displayed first three rows similarly there is one more function called a tail so this stay will give the last five rows it will display the last five rows of the table and if you pass any parameter here the tail of the number of rows the number of rows that will be displayed here if this number of rows is four some four rows will be displayed here the last four rows last four rows and there is one more function called describe describe so this will give the basic mathematical formulas applied on each and every corner so like account it will give the count the minimum value the maximum value the standard deviation average 75 value 25 value and all these things will be applied on all columns and it will be displayed right and apart from all these things we are having a one more property called shape so we can know the shape of the table right so shape will give the number of rows and columns number of rows and number of columns right so i'm just giving the overview of all these things so later after this one so i will demonstrate each and everything by executing by using one excel sheet right so shape and also slicing slicing simply we can go with here we can write the starting index stop index so here we should not call it as index we can give a row number starting row numbers top row number row number and the step step step size so the difference between different rows so by default it will be 0 by default it will be the length of a rows the last row number and this will be 1 by default these are all the see this is the maximum this is these are all the default values so just similarly which we have seen in the basic concepts like list or inputs right and if you want to access only one column then just go with the data frame so which we have created or simply give the column name column name so that only the thing will be displayed and if you want to get a multiple columns simply you can write so this is a single column and if you want to get the multiple columns data frame [Music] of give the another subscript here we can write a column one column two right so it will give the complete columns two problems from the table okay so multiple columns this gives the multiple columns and if you want to apply the slicing for this only these two columns simply you can go with data frame of give the column names column 1 column 2 so here i'm writing simply column one here you need to write the column name column name one column name two and simply give the start stop and step so this will give the slicing operation so first it will give only two columns so for those two columns we'll apply the slicing operation so like this we can apply and if you want to get the data in individual rows so first row second or third row then you need to use a for loop so i will show you for giveaway two variables that is the index value and the row value in there is a function called item rules okay so data frame dot it rows so that it will iterate one by one so simply you can print the index as well as the row so automatically each and every row will be displayed so after completion of first row the second row will be displayed after completion of second row third row will be displayed if you want to get only one row there is one more option called data frame dot loc of one this will give a single row it will give a single row or if you want to get the row of a particular value okay condition based interval then you can go with the d of df.loc so again df dot sorry so column name okay column name is equal is equal to give the value here automatically it will give the particular row with this condition okay first this condition will be executed and that particular row will be displayed here so don't worry if you are having a confusion so i will execute each and every concept which have discussed here so by using the jupyter notebook so we'll log into the jupyter notebook and i will show you so first we will read one excel so uh and then from that particular excel will create a data frame and we see all these ways how can we access the rows and columns or values from that particular data frame right so let's move on to the jupyter notebook hello friends so just now we have seen the syntax for accessing the data and also slicing operations on the data from the excel in pandas right so in the previous session we have seen how to load the data from the excel or csv file so first we will load the data from the excel file right and then we'll apply the accessing statements and see i have taken some excel sheet with some sort of students with the particular marks i will load this one and then will access the particular elements so in order to load the excel we had a function called read underscore excel so first of all we need to import the pandas and then we need to read the data and then we have to give the data as an input to the data frame right now first i will import pandas i will give some alias name some pd and see after executing this one then i will take the input d is equal to read underscore excel so i am taking the excel document so i have given some excel read underscore excel if you are dealing with the csv we can go with the read underscore csv okay now here we need to give the path copy the path here so you need to give the complete path of the file so go to the properties you can find the complete path of that particular document see you can just simply copy this one so this is the location just copy this one and paste it right hyphen marks dot x l s x and here in python we need to give it double quotations sorry double slash in the address okay i have given some double slash and executed sorry pd dot read excel okay now i have to create a data frame so df is equal to some pd dot data frame of d so i have password some d to the data frame so one data frame is created now you can observe if you print df the data will be displayed here you can observe here the index is from zero onwards okay row number name of student telugu english math science and social so there are some columns some sort of columns are there right so this is how we can create the data frame now how to access the elements so there is a function called df dot head it will give that first five rules so you can observe here there is a first five rules it will give the first five rows of the data and similarly if you want to get more number of rows df dot head and just pass the number of rows you need to get so if you want to get some seven rows just go to the seven so the complete seven rows will be displayed if you want to get only two rows you go with the two so two rows so here head function gives the rows from the beginning itself so if you pass two the first two rows from the top most two rows will be displayed if you go with the seven so topmost seven rows will be displayed right so we with if you are not giving any parameter to this head function five rows will be displayed similarly there is another function called tail so it will give last five volts it will give last five rows and here similar to our head function in tile function also you can pass the parameter so the number of rows to be displayed if you give 10 the last 10 rows will be displayed last 10 rows will be displayed here so these are the main functions to access the complete rows and also if you go with the df dot describe some sort of functions will be applied and will be displayed see for each and every column the count the count will be displayed so total 20 20 rows are there so 20 here it gives a 20. for all the columns it will apply this count and the mean for complete column elements the mean value is like this so for the first column the mean value for the second column it's a mean value right and standard deviation the minimum value what's the minimum value in the given this one right and the 25 percentage 50 days 75 percentage similarly the maximum also will be given the maximum will also be given right so like this this described function will give some the basic mathematical formulas will be applied to each and every column and it will be displayed right so this is the column sorry describe and if you want to know what are the columns available in the data frame so just go with the df dot columns so automatically it will give all the columns so you can observe here roll number name of students there will be english max science and social so these are the columns available in the given data frame right so if you want to act if you want to know the shape of the data so go with the df dot shape it will give the shape so 20 rows and seven columns one two sorry here you can observe one two three four five six and seven columns and 20 rows so there are 20 rows with the seven columns 20 rows with seven columns now how to access the single column so here we are we know that it is having some see seven columns if you want to know only a single column just go with the df of give the column name here so it is a roll underscore number so only row number will be displayed here only roll number will be displayed and if you give head if you apply the head here there will be only five elements the first five elements so i am just accessing the roll number the two only first five rows right and if you want to access more number of rows so roll number i need to get a telugu marks telugu marks right so i will give this one sorry see so you need to pass the number of columns you required in subscript so that will get a multiple rows multiple columns with the given head so if i want to get a 10 so i will just get the first 10 rows with the roll number anything and if you want to also if you if you also want to know about a number i mean another column like social so go with this one so you can get the total telugu and social marks there will go and the social marks right so like this we can also apply for the tail also so we can also replace this head to 10 so that will get the last 10 rows last 10 rows okay and then the next one is a slicing we can also give the slicing so head will give only top five rows and the tail will do only last five rows or else we can pass the argument so that that many number of rows will be displayed that is from top and bottom so if you need a range of rows if you need to display the range of rows then here also we need to use a slicing operation see i will go with the slicing see 1 to 10. see df of 1 to 10 so from first row onwards it will be displayed till the 9th row because 10 is the last element so it will not be displayed here so this is slicing so you can give the start index and stop index here so that that will be displayed and also if you can give the step size so i need to go with the two so all the two different elements will be displayed so first row third row fifth row seventh ninth row right if you go with some five we'll go only two elements one and six one and six so the student name the marks and all these things will be displayed here okay if you want to get only columns particular columns so then df off go to the column so go with the roll number roll number and comma if you want to have the name of the student see name of student and i need to get the telugu marks right i need to use the subscript here right i need to use the subscript here so if you press enter we'll get all the elements right if you want to slicing i just want only a few elements so just go with the one more this one and apply the slicing here so i just want to get the numbers give the index values so from 1 to 6 sorry yeah you can observe 1 2 6 that means from first row till fifth column and if you are not giving here one will get from zero onwards the starting index and if you are not giving some six and if you apply from five so we'll get from five to end five to end so like this we can apply the number of i mean we can apply the slicing right next single row if you want to get the single row see loc we need to apply the loc method lvc of one one means the index one row will be displayed here we can observe name of the student telugu english so the format has been changed the format has been changed okay so previously it will be a tabular table data tablet format and here we are getting the row wise this complete row wise and if you want to access multiple elements like this in a similar way go with the lvc of uh go with the slicing operation one two six so that will get the tabular format okay again we can we will get the tabular format so we can use the loc loc or directly you can go with the this one index value slicing to access multiple rows right and then if you want to apply i mean if you want to get all the rows in this fashion if you want to get all the rows in this fashion you need to go with the for loop for index rows in there is a function called it iterates it are rows iter rows it will iterate all the rows in the data frame so simply you just give index comma rows so automatically we'll get all the elements in the same fashion so in the same fashion we'll get all the rules so you can observe here roll number one name of the student marks up for different subjects and after that roll number 102 the name and marks roll number three so like that we'll get all the elements till the roll number 120 or else or else you can simply use the number of rows to be displayed here here you can pass the column name okay so if i give the name of student so we'll get only those values and if you want to get the roll number see we need to give the subscript type we need to give the subscript and here sorry sorry so yeah sorry you can get only the name of the student and roll number and if you want to get the marks simply you can add a marks also so automatically we'll get the three columns roll number name and tell you and again roll number name and table the marks of the particular student will tell you right so like this we can access row voice or in a tabular format simply if you want to get in a tablet format simply we can go with the df of some 1 to 1 to 10 so so that will get all the elements in different form right so hope you understood this one and if you want to search with the condition if you want to search with the condition just go with the df dot loc off you can search here df of column name so column name uh just go with the roll number so accessing the row okay roll number is equal to give the value here so i just want to know the details of a roll number one zero five so i'll give simply one zero five so that i will get the complete details of that particular row so if you are if you want to access the marks of a particular student we can use this one so we can pass the complete thing in lvoc so df off just to go with the name of student is equal to if i say i need to access the marks of sandy so i will get the marks of sunday so first this will be executed and that index will be executed to this location all right and that will be applied here if you go with the one more name like srinidhi receive we'll get the marks of particular students so like this we can access the values or the access the rows or columns of a table in data frame so hope you understood this session so in this session we have seen the head function tail function and how to access the columns individual columns how can we apply the slicing how can we access multiple columns okay how can we access the particular row particular row and all these things so let's stop here and if you have any doubts regarding this accessing the elements of a data frame so feel free to post your doubts in the comment section definitely i will try to clarify all your doubts and if you are real understood my session like my session share my session with your friends and don't forget to subscribe to our channel thanks for watching thank you very much
Info
Channel: Sundeep Saradhi Kanthety
Views: 5,151
Rating: 4.9506173 out of 5
Keywords: sundeep, saradhi, kanthety, python, programming, basics, fundamentals, programming concepts, modules, object, create object, import, programming fundamentals, PYTHON PROGRAMMING, PYTHON FUNDAMENTALS, interpreter, python libraries, libraries, numpy, pandas, numpy installation, python IDE, PANDAS, idle, anaconda, series, dataframe, dictionary, series creation, pandas series, excel file, csv filed, list of tuples, read_csv, read_excel, indexing, accessing, slicing, head, tail, subscribe, shape, iterrows function
Id: GmfwnZWCGdo
Channel Id: undefined
Length: 23min 18sec (1398 seconds)
Published: Tue May 04 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.