Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Returns the first n rows.
Syntax
head(n: Optional[int] = None)
Parameters
| Parameter | Type | Description |
|---|---|---|
n |
int, optional | default 1. Number of rows to return. |
Returns
If n is supplied, return a list of Row of length n or less if the DataFrame has fewer elements. If n is missing, return a single Row.
Notes
This method should only be used if the resulting array is expected to be small, as all the data is loaded into the driver's memory.
Examples
df = spark.createDataFrame([
(2, "Alice"), (5, "Bob")], schema=["age", "name"])
df.head()
# Row(age=2, name='Alice')
df.head(1)
# [Row(age=2, name='Alice')]
df.head(0)
# []