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))
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 3. Kapitel 1
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Awesome!
Completion rate improved to 2.7
The `head()` Method
Svep för att visa menyn
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))
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 3. Kapitel 1