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))
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 3. Capitolo 1
Chieda ad AI
Chieda ad AI
Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione
Suggested prompts:
Mi faccia domande su questo argomento
Riassuma questo capitolo
Mostri esempi dal mondo reale
Awesome!
Completion rate improved to 2.7
The `head()` Method
Scorri per mostrare il 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))
Tutto è chiaro?
Grazie per i tuoi commenti!
Sezione 3. Capitolo 1