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))
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 3. Capítulo 1
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Suggested prompts:
Pregunte me preguntas sobre este tema
Resumir este capítulo
Mostrar ejemplos del mundo real
Awesome!
Completion rate improved to 2.7
The `head()` Method
Desliza para mostrar el menú
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))
¿Todo estuvo claro?
¡Gracias por tus comentarios!
Sección 3. Capítulo 1