In this article, we are going to see how to display first 10 rows in Pandas DataFrame with the help of the examples. Pandas Provide a DataFrame method called head() that is used to display the number of rows passed into the head() method. It takes an integer value as a parameter and returns the same number of rows from Pandas DatFrame.
In real-life Pandas applications, sometimes we want to get first some rows to apply some as sample DataFrame to apply some functionality instead of applying the same functionality on entire rows., In that scenario, we can use a head() method that returns a specific number of rows from Pandas DataFrame.
To apply the head() method we must have a Pandas DataFrame.
Let’s create a sample Pandas DataFrame so that we can easily apply the head() method on top of that DataFrame.
Headings of Contents
Sample Pandas DataFrame
To create a sample Pandas DataFrame I have prepared a simple CSV file along with some records as you can see below.
employees.csv |
---|
emp_full_name,emp_email,emp_gender,emp_salary,emp_department,date_of_joining Mayank Kumar,[email protected],Male,25000,BPO,11/1/2023 Vishvajit Rao,[email protected],Male,40000,IT,11/2/2023 Harshita Mathur,[email protected],Female,20000,Sales,11/3/2023 Kavya Singh,[email protected],Female,20000,SEO,11/4/2023 Vishal Kumar,[email protected],Male,60000,IT,11/5/2023 Vaishali Mehta,[email protected],Female,35000,SEO,11/6/2023 Vaishali Mehta,[email protected],Female,35000,SEO,11/6/2023 James Bond,[email protected],Male,42000,IT,11/7/2023 Mariya Katherine,[email protected],Female,32000,Sales,11/8/2023 Mariya Katherine,[email protected],Female,40000,Sales,11/8/2023 Harshali Kumari,[email protected],Female,21000,BPO,11/9/2023 Vinay Singh,[email protected],Male,18000,BPO,11/10/2023 Vinay Mehra,[email protected],Male,45000,IT,11/11/2023 Akshara Singh,[email protected],Female,55000,IT,11/12/2023 |
Now, I have loaded the above CSV file using the Pandas read_csv() method.
import pandas as pd df = pd.read_csv( '../../Datasets/employees.csv' ) dfimport pandas as pd df = pd.read_csv( '../../Datasets/employees.csv' ) print(df)
Now, we have successfully loaded the CSV file into Pandas DataFrame.
Before displaying the 10 rows in Pandas DataFrame let’s see a little about the DataFrame head() method.
Pandas DataFrame head() Method
The head() is the Pandas DataFrame method that is always applied on the top of the Pandas DataFrame and it takes an integer value as a parameter that indicates the number of rows.
The head() method returns a new data frame along with a specified number of rows.
Let’s see the head() method practically.
Display First 10 Rows in Pandas DataFrame
Here we are about to display only 10 rows from the above Pandas DataFrame method. To display the first 10 rows, we need to call the head() method and pass 10 as a parameter into the head() method.
Example: Display First 10 Rows in Pandas DataFrame
import pandas as pd df = pd.read_csv( '../../Datasets/employees.csv' ) new_df = df.head(10) print(new_df)
So this is how you can display the first 10 rows in Pandas DataFrame with the help of the head() method.
Helpful Pandas Articles
- How to convert Dictionary to CSV
- How to convert YML to Dictionary
- How to convert Excel to Dictionary
- How to Convert String to DateTime in Python
- How to Sort the List Of Dictionaries By Value in Python
- How To Add a Column in Pandas Dataframe
- How to Replace Column Values in Pandas DataFrame
- How to Convert Excel to JSON in Python
- How to Drop Duplicate Rows in Pandas DataFrame
- How to use GroupBy in Pandas DataFrame
- How to convert DataFrame to HTML in Python
- How to Delete a Column in Pandas DataFrame
- How to convert SQL Query Result to Pandas DataFrame
- How to Convert Dictionary to Excel in Python
- How to Convert Excel to Dictionary in Python
- How to Rename Column Name in Pandas DataFrame
- How to Get Day Name from Date in Pandas DataFrame
- How to Split String in Pandas DataFrame Column
Conclusion
So throughout this article, we have seen how to display the first 10 rows in Pandas DataFrame method. Using this head() method you can display first any number of rows easily and perform some operations on top of the newly returned DataFrame.
if you found this article helpful, please share and keep visiting for further Pandas tutorials.