Python has many modules, but pandas is one of the best at analyzing data. The DataFrame.head()
function prints the first n
number of rows from the top of DataFrame
. It is very useful in data analysis to check dataset attributes.
# function syntaxDataFrame.head(n)
It takes the following value as an argument:
n
: This is the DataFrame
.Ifn < 0
, it will return lastn
rows ofDataFrame
.
It returns segmented DataFrame
as a series or DataFrame
.
#Import panda moduleimport pandas as panda#Import NumPy moduleimport numpy as numpy#Dataframe of students datastudents = panda.DataFrame({'Name': ['John', 'Rick', 'Alex', 'Ryan', 'Will', 'Alice'],'Marks' : ['15', '19', '10', '13', '15', '17']})#Print the first 4 rows from students dataframeprint(students.head(4))
panda
and numpy
modules. Name
and Marks
with respective data in it. students
using the DataFrame.head()
function.