![Learning pandas(Second Edition)](https://wfqqreader-1252317822.image.myqcloud.com/cover/993/36700993/b_36700993.jpg)
上QQ阅读APP看书,第一时间看更新
Heads, tails, and takes
pandas provides the .head() and .tail() methods to examine the first (head) or last (tail) few rows in a Series. By default, these return the first or last five rows, but this can be changed using the n parameter.
Let's examine the usage given the following Series:
![](https://epubservercos.yuewen.com/77D4E0/19470406901634306/epubprivate/OEBPS/Images/a92f346b-5e97-4a2b-8ec3-4bd80956715b.png?sign=1738911477-LtrwXkcsgXqf98u09BdgCgwY0yCskDtG-0-f1887c58132bcd2fa095705f5d6f97a6)
The following retrieves the first five rows:
![](https://epubservercos.yuewen.com/77D4E0/19470406901634306/epubprivate/OEBPS/Images/66c33e2a-f6ea-463d-bf59-4006de4b00f5.png?sign=1738911477-uxdaQQKfok7vLcAezY1BJA5wdjHHQNtA-0-e5497396d9fd2e60f6351149680d94e0)
The number of items can be changed using the n parameter (or just by specifying the number):
![](https://epubservercos.yuewen.com/77D4E0/19470406901634306/epubprivate/OEBPS/Images/8e8da109-f712-47d6-920d-6092d87cf51f.png?sign=1738911477-l5GM1nhRuAuIx3CvN8DOqBCzegc9w3Lm-0-b1ac57241b7e6e942d5c9e56cb78a06b)
.tail() returns the last five rows:
![](https://epubservercos.yuewen.com/77D4E0/19470406901634306/epubprivate/OEBPS/Images/c7d8a343-0d77-4db5-bacc-2c6aa6194c37.png?sign=1738911477-DFX3V00lAmWQGm1mnOfBsklfYQiY58Ao-0-6c32151e4679bf3b92e253f35806877c)
It works similarly when specifying a number other than 5:
![](https://epubservercos.yuewen.com/77D4E0/19470406901634306/epubprivate/OEBPS/Images/8ff136be-f527-4056-90f7-4529c12d4ba9.png?sign=1738911477-T4tLECK9HCdLuimoqSA8vMykXl8FvbKm-0-0e599b6457ff24811ad5892fece062ff)
The .take() method returns the rows in a series at the specified integer position:
![](https://epubservercos.yuewen.com/77D4E0/19470406901634306/epubprivate/OEBPS/Images/30782703-a2bc-4ace-a138-065d227bbe15.png?sign=1738911477-7IFadV3QVFg5IJJ9pTWIAPT312ucUx4i-0-d8321960531461b9241891ab4f044619)