DataFrame.head()

Pandas

Returns the first n rows of the DataFrame.
n : int, defalut is 5, number of rows to return.
import pandas as pd 
my_dict={'NAME':['Ravi','Raju','Alex','Ron','King','Jack'],
         'ID':[1,2,3,4,5,6],
         'MATH':[80,40,70,70,70,30],
         'ENGLISH':[80,70,40,50,60,30]}
my_data = pd.DataFrame(data=my_dict)
print(my_data.head())
Output ( by default we get 5 rows )
   NAME  ID  MATH  ENGLISH
0  Ravi   1    80       80
1  Raju   2    40       70
2  Alex   3    70       40
3   Ron   4    70       50
4  King   5    70       60
Let us change the last line only by asking 2 records
print(my_data.head(2))
Output
   NAME  ID  MATH  ENGLISH
0  Ravi   1    80       80
1  Raju   2    40       70
Reading from excel file and displaying first n records.
import pandas as pd 
my_data = pd.read_excel('D:\student.xlsx',index_col='id')
print(my_data.head(3)
You can check the code and output at Exercise 1

str.contains.sum()

Pandas read_csv() read_excel() to_excel()


plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer