- pandas.DataFrame.head#
- pandas.DataFrame.head#
- pandas.DataFrame.head#
- Как использовать функцию Pandas head() (с примерами)
- Пример 1: просмотр первых 5 строк DataFrame
- Пример 2: просмотр первых n строк DataFrame
- Пример 3: просмотр первых n строк определенного столбца
- Пример 4. Просмотр первых n строк нескольких столбцов
- Дополнительные ресурсы
pandas.DataFrame.head#
This function returns the first n rows for the object based on position. It is useful for quickly testing if your object has the right type of data in it.
For negative values of n , this function returns all rows except the last |n| rows, equivalent to df[:n] .
If n is larger than the number of rows, this function returns all rows.
Parameters n int, default 5
Returns same type as caller
The first n rows of the caller object.
>>> df = pd.DataFrame('animal': ['alligator', 'bee', 'falcon', 'lion', . 'monkey', 'parrot', 'shark', 'whale', 'zebra']>) >>> df animal 0 alligator 1 bee 2 falcon 3 lion 4 monkey 5 parrot 6 shark 7 whale 8 zebra
Viewing the first 5 lines
>>> df.head() animal 0 alligator 1 bee 2 falcon 3 lion 4 monkey
Viewing the first n lines (three in this case)
>>> df.head(3) animal 0 alligator 1 bee 2 falcon
>>> df.head(-3) animal 0 alligator 1 bee 2 falcon 3 lion 4 monkey 5 parrot
pandas.DataFrame.head#
This function returns the first n rows for the object based on position. It is useful for quickly testing if your object has the right type of data in it.
For negative values of n , this function returns all rows except the last |n| rows, equivalent to df[:n] .
If n is larger than the number of rows, this function returns all rows.
Parameters n int, default 5
Returns same type as caller
The first n rows of the caller object.
>>> df = pd.DataFrame('animal': ['alligator', 'bee', 'falcon', 'lion', . 'monkey', 'parrot', 'shark', 'whale', 'zebra']>) >>> df animal 0 alligator 1 bee 2 falcon 3 lion 4 monkey 5 parrot 6 shark 7 whale 8 zebra
Viewing the first 5 lines
>>> df.head() animal 0 alligator 1 bee 2 falcon 3 lion 4 monkey
Viewing the first n lines (three in this case)
>>> df.head(3) animal 0 alligator 1 bee 2 falcon
>>> df.head(-3) animal 0 alligator 1 bee 2 falcon 3 lion 4 monkey 5 parrot
pandas.DataFrame.head#
This function returns the first n rows for the object based on position. It is useful for quickly testing if your object has the right type of data in it.
For negative values of n , this function returns all rows except the last |n| rows, equivalent to df[:n] .
If n is larger than the number of rows, this function returns all rows.
Parameters : n int, default 5
Returns : same type as caller
The first n rows of the caller object.
>>> df = pd.DataFrame('animal': ['alligator', 'bee', 'falcon', 'lion', . 'monkey', 'parrot', 'shark', 'whale', 'zebra']>) >>> df animal 0 alligator 1 bee 2 falcon 3 lion 4 monkey 5 parrot 6 shark 7 whale 8 zebra
Viewing the first 5 lines
>>> df.head() animal 0 alligator 1 bee 2 falcon 3 lion 4 monkey
Viewing the first n lines (three in this case)
>>> df.head(3) animal 0 alligator 1 bee 2 falcon
>>> df.head(-3) animal 0 alligator 1 bee 2 falcon 3 lion 4 monkey 5 parrot
Как использовать функцию Pandas head() (с примерами)
Вы можете использовать функцию head() для просмотра первых n строк кадра данных pandas.
Эта функция использует следующий базовый синтаксис:
В следующих примерах показано, как использовать этот синтаксис на практике со следующими пандами DataFrame:
import pandas as pd #create DataFrame df = pd.DataFrame() #view DataFrame df points assists rebounds 0 25 5 11 1 12 7 8 2 15 7 10 3 14 9 6 4 19 12 6 5 23 9 5 6 25 9 9 7 29 4 12
Пример 1: просмотр первых 5 строк DataFrame
По умолчанию функция head() отображает первые пять строк DataFrame:
#view first five rows of DataFrame df.head () points assists rebounds 0 25 5 11 1 12 7 8 2 15 7 10 3 14 9 6 4 19 12 6
Пример 2: просмотр первых n строк DataFrame
Мы можем использовать аргумент n для просмотра первых n строк кадра данных pandas:
#view first three rows of DataFrame df.head (n= 3 ) points assists rebounds 0 25 5 11 1 12 7 8 2 15 7 10
Пример 3: просмотр первых n строк определенного столбца
В следующем коде показано, как просмотреть первые пять строк определенного столбца в DataFrame:
#view first five rows of values in 'points' column df['points'].head() 0 25 1 12 2 15 3 14 4 19 Name: points, dtype: int64
Пример 4. Просмотр первых n строк нескольких столбцов
В следующем коде показано, как просмотреть первые пять строк нескольких определенных столбцов в DataFrame:
#view first five rows of values in 'points' and 'assists' columns df[['points', 'assists']].head() points assists 0 25 5 1 12 7 2 15 7 3 14 9 4 19 12
Дополнительные ресурсы
В следующих руководствах объясняется, как выполнять другие распространенные функции в pandas: