![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=1739316487-SBnvdrfzP5blojOu7Sonoiqy8qzVEdni-0-dbddcc1dba642a02dd33a842dad55355)
The following retrieves the first five rows:
![](https://epubservercos.yuewen.com/77D4E0/19470406901634306/epubprivate/OEBPS/Images/66c33e2a-f6ea-463d-bf59-4006de4b00f5.png?sign=1739316487-OeTh6RZWEc99FRLZi0X1i5Jzx7UllELL-0-ea11e163d46ba82b071aac9d0c16d70a)
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=1739316487-s6AubD8Pqi9wBBsaIeBfk1gloz3mCe1k-0-870538844e0ffb6d83197c05f27fe784)
.tail() returns the last five rows:
![](https://epubservercos.yuewen.com/77D4E0/19470406901634306/epubprivate/OEBPS/Images/c7d8a343-0d77-4db5-bacc-2c6aa6194c37.png?sign=1739316487-9jHGd9K973ONnVeFs3q1Gc8VaKaEpvoX-0-bfed44ca8aaf7d4f24dd2d833fa66d25)
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=1739316487-uERBvSR6vEkclB6MQcZkVV6nCgidgrPQ-0-15f413fb3444d2810047c3605cec2d46)
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=1739316487-h3O9Ho8tNJ5FqNv1GkEGfH0joWL086yv-0-ed3a77c1b64473d772c1ffea947a23c2)