Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (16.4k points)

In R, I would be able to use head(),but I don't know how to do that in python

Wen I enter 

df.head(10), I get...

<class 'pandas.core.frame.DataFrame'>

Int64Index: 10 entries, 0 to 9

Data columns (total 14 columns):

#Book_Date            10  non-null values

Item_Qty              10  non-null values

Item_id               10  non-null values

Location_id           10  non-null values

MFG_Discount          10  non-null values

Sale_Revenue          10  non-null values

Sales_Flg             10  non-null values

Sell_Unit_Cost        5  non-null values

Store_Discount        10  non-null values

Transaction_Id        10  non-null values

Unit_Cost_Amt         10  non-null values

Unit_Received_Cost    5  non-null values

Unnamed: 0            10  non-null values

Weight                10  non-null values

1 Answer

0 votes
by (26.4k points)
edited by

If you want to get the first 10 rows and last 10 rows of iris dataset

In case of R, the code will be

data(iris)

head(iris, 10)

tail(iris, 10)

In case of python,

import pandas as pd

from sklearn import datasets

iris = pd.DataFrame(datasets.load_iris().data)

iris.head(10)

iris.tail(10)

To load the iris dataset, you have to import scikit-learn package

Are you interested to learn python in detail? Join the python certification course and get certified

Related questions

Browse Categories

...