DataFrame.head

DataFrame.head(n=5)
返回前n行。
对于n的负值,此函数返回除最后n行之外的所有行,相当于:df[:, -n]

Parameters

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.head(3)
  7. -----------------------------------------------------------------
  8. site age price color
  9. 0 google 18 1.0 red
  10. 1 baidu 39 2.0 black
  11. 2 wiki 22 3.0 None

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.head(-2)
  7. ---------------------------------------------------------
  8. site age price color
  9. 0 google 18 1.0 red
  10. 1 baidu 39 2.0 black