The head() method in Pandas
The head() method in Pandas is used to display the first few rows of a DataFrame or Series. By default, it shows the first 5 rows, but you can specify the number of rows you want to see by passing an argument.
Syntax a) DataFrame.head(n=5)
b) Series.head(n=5)
The parameter n is an integer that specifies the number of rows to display. By default, if we have not specified the value of n then it is 5. If n is larger than the number of rows, this function returns all rows.
Example: We want to extract the first 4 rows from the dataframe.
Python
mydata=pd.read_csv("employees.csv") # We can use the following syntax # mydata.head(n=4) # mydata.head() mydata.head(4)
The output of the above code is shown below: