![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=1734432369-tKKWR3Y9uM7WjYjYGNj8plJbtKygd8zh-0-db0ba7e9ca2dbccca780f832556ee831)
The following retrieves the first five rows:
![](https://epubservercos.yuewen.com/77D4E0/19470406901634306/epubprivate/OEBPS/Images/66c33e2a-f6ea-463d-bf59-4006de4b00f5.png?sign=1734432369-0ALJ9lbHlcJEvphh46wNx6yBXiAdfneQ-0-9d265184f36dbe02e8a9fd48d37d9956)
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=1734432369-4NPtDqiZaRL8qzJlBrAgkv94BZuTFqOt-0-d61f30d1f54d92fc28dca9cfd17f39ce)
.tail() returns the last five rows:
![](https://epubservercos.yuewen.com/77D4E0/19470406901634306/epubprivate/OEBPS/Images/c7d8a343-0d77-4db5-bacc-2c6aa6194c37.png?sign=1734432369-BTDbyGbHEiHilA8c7rqS6BriuPG6FRrB-0-69ab19246d5325efb62c8f4c19424b7e)
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=1734432369-dgXBHeESQjFzxdGGJY9yBLlr9EIaFUOt-0-387b2faad6a776caaac2456bd48ac8ac)
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=1734432369-G3Mz55AwXSeqxNC49YORBLCOhqPsYxxk-0-9bdf23dfaf175e84dacde43259467b89)