Python equivalent of R's head and tail function

wolfsatthedoor

I want to preview a Pandas dataframe. I would use head(mymatrix) in R, but I do not know how to do this in Pandas Python.

When I type

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
essicolo

Suppose you want to output the first and last 10 rows of the iris data set.

In R:

data(iris)
head(iris, 10)
tail(iris, 10)

In Python (scikit-learn required to load the iris data set):

import pandas as pd
from sklearn import datasets
iris = pd.DataFrame(datasets.load_iris().data)
iris.head(10)
iris.tail(10)

Now, as previously answered, if your data frame is too large for the display you use in the terminal, a summary is output. To visualize your data in a terminal, you could either expend the terminal or reduce the number of columns to display, as follows.

iris.ix[:,1:2].head(10)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Python's equivalent for R's dput() function

From Dev

Is there a Python equivalent to R's sample() function?

From Dev

Python equivalent of R "split"-function

From Dev

R equivalent to the Python function "dir"?

From Dev

Equivalent of R's createDataPartition in Python

From Dev

Equivalent of R's removeSparseTerms in Python

From Dev

Haskell's head tail init and last in GHCi

From Dev

Tail function on factor in R

From Dev

python pandas select both head and tail

From Java

Equivalent of R's factor function in Pandas

From Dev

R: Is there an equivalent of Stata's ibn. function?

From Dev

equivalent of R's View for Python's pandas

From Dev

What is python's equivalent of R's NA?

From Dev

Matlab equivalent of Python's 'reduce' function

From Dev

Is there a Python equivalent to MATLAB's pearsrnd function?

From Dev

Is there an equivalent to Python's all function in JavaScript or jQuery?

From Dev

What is the Java equivalent to Python's reduce function?

From Dev

Pandas equivalent of Python's readlines function

From Dev

Is there an equivalent to Python's exec() function in Java?

From Dev

Equivalent of Python's dir function in PHP

From Dev

Is there a python ReportLab equivalent of TCPDF's 'annotate' function?

From Dev

Is there a C# equivalent to python's type() function?

From Dev

Python equivalent to Matlab's set function

From Dev

What is the Python Equivalent of Batch's PAUSE function

From Dev

Matlab equivalent of Python's 'reduce' function

From Dev

Python numpy or pandas equivalent of the R function sweep()

From Dev

Python equivalent of R apply with anonymous function

From Dev

Equivalent of R function 'ave' in Python Pandas

From Dev

Does 'statsmodels' or another Python package offer an equivalent to R's 'step' function?

Related Related

  1. 1

    Python's equivalent for R's dput() function

  2. 2

    Is there a Python equivalent to R's sample() function?

  3. 3

    Python equivalent of R "split"-function

  4. 4

    R equivalent to the Python function "dir"?

  5. 5

    Equivalent of R's createDataPartition in Python

  6. 6

    Equivalent of R's removeSparseTerms in Python

  7. 7

    Haskell's head tail init and last in GHCi

  8. 8

    Tail function on factor in R

  9. 9

    python pandas select both head and tail

  10. 10

    Equivalent of R's factor function in Pandas

  11. 11

    R: Is there an equivalent of Stata's ibn. function?

  12. 12

    equivalent of R's View for Python's pandas

  13. 13

    What is python's equivalent of R's NA?

  14. 14

    Matlab equivalent of Python's 'reduce' function

  15. 15

    Is there a Python equivalent to MATLAB's pearsrnd function?

  16. 16

    Is there an equivalent to Python's all function in JavaScript or jQuery?

  17. 17

    What is the Java equivalent to Python's reduce function?

  18. 18

    Pandas equivalent of Python's readlines function

  19. 19

    Is there an equivalent to Python's exec() function in Java?

  20. 20

    Equivalent of Python's dir function in PHP

  21. 21

    Is there a python ReportLab equivalent of TCPDF's 'annotate' function?

  22. 22

    Is there a C# equivalent to python's type() function?

  23. 23

    Python equivalent to Matlab's set function

  24. 24

    What is the Python Equivalent of Batch's PAUSE function

  25. 25

    Matlab equivalent of Python's 'reduce' function

  26. 26

    Python numpy or pandas equivalent of the R function sweep()

  27. 27

    Python equivalent of R apply with anonymous function

  28. 28

    Equivalent of R function 'ave' in Python Pandas

  29. 29

    Does 'statsmodels' or another Python package offer an equivalent to R's 'step' function?

HotTag

Archive