DataFrame.tail

DataFrame.tail(n=5)
返回最后n行。
对于n的负值,此函数返回除前n行之外的所有行。

Example

  1. import pandas as pd
  2. df = pd.DataFrame({'site':['google', 'baidu', 'wiki', 'pandas'],
  3. 'age':[18, 39, 22, 45],
  4. 'price': [1.0, 2.0, 3.0, 4.0],
  5. 'color': ['red', 'black', None, 'red']})
  6. df.tail(3)
  7. --------------------------------------------------------
  8. site age price color
  9. 1 baidu 39 2.0 black
  10. 2 wiki 22 3.0 None
  11. 3 pandas 45 4.0 red

Example

  1. import pandas as pd
  2. df = pd.DataFrame({'site':['google', 'baidu', 'wiki', 'pandas'],
  3. 'age':[18, 39, 22, 45],
  4. 'price': [1.0, 2.0, 3.0, 4.0],
  5. 'color': ['red', 'black', None, 'red']})
  6. df.tail(-3)
  7. ------------------------------------------------------
  8. site age price color
  9. 3 pandas 45 4.0 red