Pandas dataframe allows you to manipulate datasets after their conversion to dataframe. There are many inbuilt functions in the pandas dataframe that allow you to do. In this tutorial, you will know how How to Print the First 10 Rows of Pandas Dataframe steps.

## Syntax of the function

In this section, you will know the syntax of the function that will be used for printing the first 10 rows of the pandas dataframe. And it is head() function. The syntax of the head is below.

`your_df(n)`

Here n is the number of the rows you want to print. However if you don’t put any n values as the argument for the head() function then by default the first five rows will be printed.

## Steps to Print First 10 Rows of Pandas Dataframe

Let’s know all the steps you will follow to print the first ten rows of the dataframe. For better understanding please follow the same.

### Step 1: Import the required libraries

The first step is to import all the necessary libraries. Here I am using the numpy and pandas modules. The numpy module will be use only for dataframe creation. Let’s import them using the import statement.

```
import pandas as pd
import numpy as np
```

### Step 2: Create a sample dataframe.

Now for the implementation let’s create a sample dataframe. Use the below lines of code to create the dummy dataframe.

```
import numpy as np
import pandas as pd
np.random.seed(0)
df = pd.DataFrame({'col1': list('abcdefghipqrstuv'), 'col2': np.random.choice(10, 16)})
df
```

**Output**

### Step 3: Use the head() function

The third step is to use the head() function to select the rows of the dataframe. For Selecting the first 10 rows you have to pass the value of n =10. Use the below lines of code to select the first ten rows.

`df.head(n=10)`

### Step 4: Print the First 10 Rows of Pandas Dataframe

Now use the print(head(10)) to print out the first ten rows of the pandas dataframe.

Below is the full code of this example.

```
import numpy as np
import pandas as pd
np.random.seed(0)
df = pd.DataFrame({'col1': list('abcdefghipqrstuv'), 'col2': np.random.choice(10, 16)})
print(df.head(n=10))
```

**Output**

## Conclusion

In this tutorial, you have learned how to use the head() function to print the first 10 rows of the pandas dataframe. In the same way, if you put the value of n =20 then the first 20 rows will be selected. You can also use the* df.iloc[:10]* to display the first ten rows of the pandas dataframe.

I hope you have liked this tutorial. If you have any queries then you can contact us for more help.

#### Join our list

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.