![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=1739213450-1PCjvh3xmBoKS6TinzVDGbfjkTPxPvDW-0-ecad96fdc467cdf6e41b67d0ab3ed872)
The following retrieves the first five rows:
![](https://epubservercos.yuewen.com/77D4E0/19470406901634306/epubprivate/OEBPS/Images/66c33e2a-f6ea-463d-bf59-4006de4b00f5.png?sign=1739213450-4hwcwBkweGl9k7Mw6i1ooN9aB9BSnwz8-0-60bf64b98ba1533a8c189273b362ddc9)
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=1739213450-bda8DE0dbQctcGONXn0wGHtErdEk4FKm-0-694b0522dce7dac77aee5d2b6993d320)
.tail() returns the last five rows:
![](https://epubservercos.yuewen.com/77D4E0/19470406901634306/epubprivate/OEBPS/Images/c7d8a343-0d77-4db5-bacc-2c6aa6194c37.png?sign=1739213450-0GySnrlM4eMXMousgvWhZNRuNVoJ2J71-0-757ca23ec59970b5a25da6c579b5cae6)
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=1739213450-jwU5RXKtbZGBsENUvyhG5N6CA4Euf4sK-0-cf7da7e30bf53731c63cecdca6e025a8)
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=1739213450-V7qIt1CeTZeA1ZbtvVlFYt8J61giSMz1-0-7aab98a17f40f703ed0d0e87c20bb370)