Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.head#

DataFrame.head(n=5)[source]#

Return the firstn rows.

This function returns the firstn rows for the object basedon position. It is useful for quickly testing if your objecthas the right type of data in it.

For negative values ofn, this function returns all rows exceptthe last|n| rows, equivalent todf[:n].

If n is larger than the number of rows, this function returns all rows.

Parameters:
nint, default 5

Number of rows to select.

Returns:
same type as caller

The firstn rows of the caller object.

See also

DataFrame.tail

Returns the lastn rows.

Examples

>>>df=pd.DataFrame({'animal':['alligator','bee','falcon','lion',...'monkey','parrot','shark','whale','zebra']})>>>df      animal0  alligator1        bee2     falcon3       lion4     monkey5     parrot6      shark7      whale8      zebra

Viewing the first 5 lines

>>>df.head()      animal0  alligator1        bee2     falcon3       lion4     monkey

Viewing the firstn lines (three in this case)

>>>df.head(3)      animal0  alligator1        bee2     falcon

For negative values ofn

>>>df.head(-3)      animal0  alligator1        bee2     falcon3       lion4     monkey5     parrot

[8]ページ先頭

©2009-2025 Movatter.jp