The `head()` Method
The head()
method is used to fetch the first few rows of a DataFrame.
By default, it fetches the first 5
rows, but you can specify how many rows you want using the n
named paramter.
Syntax:
DataFrame.head(n=5)
Example:
123456789101112131415import pandas as pd # Create a simple DataFrame data = { 'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eva', 'Frank'], 'Age': [24, 30, 22, 29, 25, 28] } df = pd.DataFrame(data) print('Show the first 5 rows:') print(df.head()) print('Show the first 3 rows:') print(df.head(3))
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 3. Capítulo 1
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Awesome!
Completion rate improved to 2.7
The `head()` Method
Deslize para mostrar o menu
The head()
method is used to fetch the first few rows of a DataFrame.
By default, it fetches the first 5
rows, but you can specify how many rows you want using the n
named paramter.
Syntax:
DataFrame.head(n=5)
Example:
123456789101112131415import pandas as pd # Create a simple DataFrame data = { 'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eva', 'Frank'], 'Age': [24, 30, 22, 29, 25, 28] } df = pd.DataFrame(data) print('Show the first 5 rows:') print(df.head()) print('Show the first 3 rows:') print(df.head(3))
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 3. Capítulo 1