![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=1739374634-SbDgI3DkH4LUkch0rfNFz8fhQiCVpFdV-0-a6cce9992348863a29f67207a6adbc28)
The following retrieves the first five rows:
![](https://epubservercos.yuewen.com/77D4E0/19470406901634306/epubprivate/OEBPS/Images/66c33e2a-f6ea-463d-bf59-4006de4b00f5.png?sign=1739374634-ERom2cNP7T6uFrqjUKi6NHTqHxnHbkw8-0-430829a7bbbddf55ff5bd50e9ed9b9ab)
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=1739374634-lgD50NJkdfgLcgqnLlGhleLovMfgFZlX-0-89dec1cd3192438fc4fd9a808ddd4f91)
.tail() returns the last five rows:
![](https://epubservercos.yuewen.com/77D4E0/19470406901634306/epubprivate/OEBPS/Images/c7d8a343-0d77-4db5-bacc-2c6aa6194c37.png?sign=1739374634-kxoPHBx8xlv3bePkxp59trPlqYUGuHVs-0-7947e74d2015785f9452286acdf26578)
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=1739374634-1wDeMrfuRRqDE9FIOTymduVf8weviRTA-0-78a3eb84eaa85d645f3dc76a7efe72fd)
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=1739374634-H3MOv2aY3NOuslgmkaIhDQmfZYhIlTie-0-ea0207eef641a59dabe2766930a97e97)