Basic Methods/Attributes of Dataframe
Dataset: Exam Scores
This dataset contains marks secured by different students in an examination and their background information.
The dataset can be found here:
Read The dataset
So far you have learned how to read a csv file using read_csv() function. Let’s see the practical implementation
read_csv() function is of pandas library. So the first task is always to import/load the library we will use.
To read a csv file, use read_csv() function of pandas library.
The csv file ‘exam_scores’ is located in the current working direcroy
Methods/Attributes of Dataframe
shape attribute
shape: It will help you to know what is the shape of your Dataframe i.e. (number of rows, number of columns)
After we have loaded the data we can check the shape of the Dataframe using shape attribute.
So our DataFrame has 1000 rows and 8 columns. From here we can also say that our DataFrame has 8000 entries.
head( ) method
head( ): It will help you to see the first five observations of your dataframe. You can get some idea about the content of your dataframe.
To get some idea about the content in the dataframe we can use head() or tail() method. Any one of the two can give us some idea about the content in the dataframe
We can see the first five observation of the dataset in the above table.
tail( ) method
tail( ): This method is similar to head() method but instead of first five it will give you the last five observation from your dataset.
We can see the last five observation of the dataset in the above table.
head( ) and tail( )
We can also add the number of rows to be displayed in both head( ) and tail( ). See the example below:
dtypes
dtypes attribute: It will help you know about the data types of each column.
To know the data types associated with each column, we can use dtypes attribute.
We can observe here that the columns -
'gender', 'race/ethnicity', 'parental level of education', 'lunch' and 'test preparation course' are of data type - object.
'math score', 'reading score' and 'writing score' are of data type - int64 (i.e. integer)
info( )
info( ) method: This method will return you a concise summary about the dataframe.
What you get using info() method?
Last updated
Was this helpful?