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))
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 3. Luku 1
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Suggested prompts:
Kysy minulta kysymyksiä tästä aiheesta
Tiivistä tämä luku
Näytä käytännön esimerkkejä
Awesome!
Completion rate improved to 2.7
The `head()` Method
Pyyhkäise näyttääksesi valikon
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))
Oliko kaikki selvää?
Kiitos palautteestasi!
Osio 3. Luku 1