Pandas Series: tail() function
Series-tail() function
The tail() function is used to return the last n rows.
This function returns last n rows from the object based on position. It is useful for quickly verifying data, for example, after sorting or appending rows.
Syntax:
Series.tail(self, n=5)
Parameters:
Name | Description | Type/Default Value | Required / Optional |
---|---|---|---|
n | Number of rows to select. | int< Default Value: 5 |
Required |
Returns: type of caller
The last n rows of the caller object.
Example:
Python-Pandas Code:
import numpy as np
import pandas as pd
df = pd.DataFrame({'animal':['dog', 'bee', 'cat', 'lion',
'monkey', 'tiger', 'fox', 'wolf', 'zebra']})
df
Output:
animal 0 dog 1 bee 2 cat 3 lion 4 monkey 5 tiger 6 fox 7 wolf 8 zebra
Example - Viewing the last 5 lines:
Python-Pandas Code:
import numpy as np
import pandas as pd
df = pd.DataFrame({'animal':['dog', 'bee', 'cat', 'lion',
'monkey', 'tiger', 'fox', 'wolf', 'zebra']})
df.tail()
Output:
animal 4 monkey 5 tiger 6 fox 7 wolf 8 zebra
Example - Viewing the last n lines (three in this case):
Python-Pandas Code:
import numpy as np
import pandas as pd
df = pd.DataFrame({'animal':['dog', 'bee', 'cat', 'lion',
'monkey', 'tiger', 'fox', 'wolf', 'zebra']})
df.tail(3)
Output:
animal 6 fox 7 wolf 8 zebra
Previous: Series-take() function
Next: Series-truncate() function
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/pandas/series/series-tail.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics