TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Pandas DataFrame.head()

Pandas DataFrame.head() with What is Python Pandas, Reading Multiple Files, Null values, Multiple index, Application, Application Basics, Resampling, Plotting the data, Moving windows functions, Series, Read the file, Data operations, Filter Data etc.

<< Back to PANDAS

Pandas DataFrame.head()

The head() returns the first n rows for the object based on position. If your object has the right type of data in it, it is useful for quick testing. This method is used for returning top n (by default value 5) rows of a data frame or series.

Syntax

DataFrame.head(n=5)

Parameters

n: It refers to an integer value that returns the number of rows.

Return

It returns the DataFrame with top n rows.

Example1

info = pd.DataFrame({'language':['C', 'C++', 'Python', 'Java','PHP']})
info.head()
info.head(3)

Output

       language
0        C
1       C++
2       Python

Example 2

We have a csv file "aa.csv" that have the following dataset.

     Name               Hire Date    Salary      Leaves Remaining
0   John Idle           03/15/14     50000.0       10
1   Smith Gilliam       06/01/15     65000.0       8
2   Parker Chapman      05/12/14     45000.0       10
3   Jones Palin         11/01/13     70000.0       3
4   Terry Gilliam       08/12/14     48000.0       7

By using the head() in the below example, we showed only top 2 rows from the dataset.

# importing pandas module 
import pandas as pd  
# making data frame 
data = pd.read_csv("aa.csv")   
# calling head() method  
# storing in new variable 
data_top  = data.head(2)  
# display 
data_top

       Name          Hire Date      Salary      Leaves Remaining
0     John Idle        03/15/14     50000.0        10
1     Smith Gilliam    06/01/15     65000.0        8

Next TopicDataFrame.hist()




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf