当前位置:   article > 正文

Pandas中head( )函数_pandas head

pandas head

Pandas读取数据之后使用pandas的head()函数的时候,来观察一下读取的数据

head( )函数只能读取前五行数据如下图所示

在查看这个head()函数的具体实现如下:

  1. def head(self, n=5):
  2. """
  3. Return the first `n` rows.
  4. This function returns the first `n` rows for the object based
  5. on position. It is useful for quickly testing if your object
  6. has the right type of data in it.
  7. Parameters
  8. ----------
  9. n : int, default 5
  10. Number of rows to select.
  11. Returns
  12. -------
  13. obj_head : same type as caller
  14. The first `n` rows of the caller object.
  15. See Also
  16. --------
  17. DataFrame.tail: Returns the last `n` rows.
  18. Examples
  19. --------
  20. >>> df = pd.DataFrame({'animal':['alligator', 'bee', 'falcon', 'lion',
  21. ... 'monkey', 'parrot', 'shark', 'whale', 'zebra']})
  22. >>> df
  23. animal
  24. 0 alligator
  25. 1 bee
  26. 2 falcon
  27. 3 lion
  28. 4 monkey
  29. 5 parrot
  30. 6 shark
  31. 7 whale
  32. 8 zebra
  33. Viewing the first 5 lines
  34. >>> df.head()
  35. animal
  36. 0 alligator
  37. 1 bee
  38. 2 falcon
  39. 3 lion
  40. 4 monkey
  41. Viewing the first `n` lines (three in this case)
  42. >>> df.head(3)
  43. animal
  44. 0 alligator
  45. 1 bee
  46. 2 falcon
  47. """
  48. return self.iloc[:n]

从中可以看出默认的时候是查看5行,

如果想输出3行或者多行

 

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号