w3resource

Pandas: Display the first 10 rows of the DataFrame


9. Display First 10 Rows

Write a Pandas program to display the first 10 rows of the DataFrame.

Sample Solution:

Python Code :

import pandas as pd
df = pd.read_csv('movies_metadata.csv')
#Display the first 10 rows
result = df.head(10)
print("First 10 rows of the DataFrame:")
print(result)

Sample Output:

First 10 rows of the DataFrame:
   adult    ...     vote_count
0  False    ...           5415
1  False    ...           2413
2  False    ...             92
3  False    ...             34
4  False    ...            173
5  False    ...           1886
6  False    ...            141
7  False    ...             45
8  False    ...            174
9  False    ...           1194

[10 rows x 24 columns]                                     

For more Practice: Solve these Related Problems:

  • Write a Pandas program to load movies_metadata.csv and display the first 10 rows using the head() function.
  • Write a Pandas program to show the top 10 records and verify that the index ranges from 0 to 9.
  • Write a Pandas program to display the first 10 rows and then print the data types of each column in these rows.
  • Write a Pandas program to load movies_metadata.csv and display the first 10 rows with a custom header added to the output.

Go to:


Previous: Write a Pandas program to create a smaller with a subset of all features.
Next: Write a Pandas program to sort the DataFrame based on release_date.

Python-Pandas Code Editor:

Sample Table:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.