Vì vậy, để có được ba hàng đầu tiên của DataFrame, chúng ta có thể gán giá trị của N là '3' ..
Cú pháp: DataFrame.head (n).
Cú pháp: dataFrame.iloc [statrt_index, end_index+1].
Cú pháp: dataFrame.iloc [[m, n]].Xem thảo luậnVì vậy, để có được ba hàng đầu tiên của DataFrame, chúng ta có thể gán giá trị của N là '3' ..
Cú pháp: DataFrame.head (n).
Cú pháp: dataFrame.iloc [statrt_index, end_index+1].
Cú pháp: dataFrame.iloc [[m, n]].
import
pandas as pd
dict
=
{
'Name'
import pandas as pd
#initialize a dataframe
df = pd.DataFrame(
[[21, 72, 67],
[23, 78, 62],
[32, 74, 56],
[73, 88, 67],
[32, 74, 56],
[43, 78, 69],
[32, 74, 54],
[52, 54, 76]],
columns=['a', 'b', 'c'])
#get first default number of rows
df1 = df.head()
#print the dataframe
print(df1)
4import pandas as pd
#initialize a dataframe
df = pd.DataFrame(
[[21, 72, 67],
[23, 78, 62],
[32, 74, 56],
[73, 88, 67],
[32, 74, 56],
[43, 78, 69],
[32, 74, 54],
[52, 54, 76]],
columns=['a', 'b', 'c'])
#get first default number of rows
df1 = df.head()
#print the dataframe
print(df1)
5import pandas as pd
#initialize a dataframe
df = pd.DataFrame(
[[21, 72, 67],
[23, 78, 62],
[32, 74, 56],
[73, 88, 67],
[32, 74, 56],
[43, 78, 69],
[32, 74, 54],
[52, 54, 76]],
columns=['a', 'b', 'c'])
#get first default number of rows
df1 = df.head()
#print the dataframe
print(df1)
1import pandas as pd
#initialize a dataframe
df = pd.DataFrame(
[[21, 72, 67],
[23, 78, 62],
[32, 74, 56],
[73, 88, 67],
[32, 74, 56],
[43, 78, 69],
[32, 74, 54],
[52, 54, 76]],
columns=['a', 'b', 'c'])
#get first default number of rows
df1 = df.head()
#print the dataframe
print(df1)
7import pandas as pd
#initialize a dataframe
df = pd.DataFrame(
[[21, 72, 67],
[23, 78, 62],
[32, 74, 56],
[73, 88, 67],
[32, 74, 56],
[43, 78, 69],
[32, 74, 54],
[52, 54, 76]],
columns=['a', 'b', 'c'])
#get first default number of rows
df1 = df.head()
#print the dataframe
print(df1)
3import pandas as pd
#initialize a dataframe
df = pd.DataFrame(
[[21, 72, 67],
[23, 78, 62],
[32, 74, 56],
[73, 88, 67],
[32, 74, 56],
[43, 78, 69],
[32, 74, 54],
[52, 54, 76]],
columns=['a', 'b', 'c'])
#get first default number of rows
df1 = df.head()
#print the dataframe
print(df1)
4pandas.DataFrame.head()
0pandas.DataFrame.head()
1pandas.DataFrame.head()
2pandas.DataFrame.head()
3pandas.DataFrame.head()
4pandas.DataFrame.head()
5
import pandas as pd
#initialize a dataframe
df = pd.DataFrame(
[[21, 72, 67],
[23, 78, 62],
[32, 74, 56],
[73, 88, 67],
[32, 74, 56],
[43, 78, 69],
[32, 74, 54],
[52, 54, 76]],
columns=['a', 'b', 'c'])
#get first default number of rows
df1 = df.head()
#print the dataframe
print(df1)
1pandas.DataFrame.head()
7import pandas as pd
#initialize a dataframe
df = pd.DataFrame(
[[21, 72, 67],
[23, 78, 62],
[32, 74, 56],
[73, 88, 67],
[32, 74, 56],
[43, 78, 69],
[32, 74, 54],
[52, 54, 76]],
columns=['a', 'b', 'c'])
#get first default number of rows
df1 = df.head()
#print the dataframe
print(df1)
1pandas.DataFrame.head()
9import pandas as pd
#initialize a dataframe
df = pd.DataFrame(
[[21, 72, 67],
[23, 78, 62],
[32, 74, 56],
[73, 88, 67],
[32, 74, 56],
[43, 78, 69],
[32, 74, 54],
[52, 54, 76]],
columns=['a', 'b', 'c'])
#get first default number of rows
df1 = df.head()
#print the dataframe
print(df1)
1import
1import pandas as pd
#initialize a dataframe
df = pd.DataFrame(
[[21, 72, 67],
[23, 78, 62],
[32, 74, 56],
[73, 88, 67],
[32, 74, 56],
[43, 78, 69],
[32, 74, 54],
[52, 54, 76]],
columns=['a', 'b', 'c'])
#get first default number of rows
df1 = df.head()
#print the dataframe
print(df1)
1pandas.DataFrame.head()
5pandas.DataFrame.head()
1pandas.DataFrame.head()
2import
6pandas.DataFrame.head()
4import
8
import pandas as pd
#initialize a dataframe
df = pd.DataFrame(
[[21, 72, 67],
[23, 78, 62],
[32, 74, 56],
[73, 88, 67],
[32, 74, 56],
[43, 78, 69],
[32, 74, 54],
[52, 54, 76]],
columns=['a', 'b', 'c'])
#get first default number of rows
df1 = df.head()
#print the dataframe
print(df1)
1pandas as pd
0import pandas as pd
#initialize a dataframe
df = pd.DataFrame(
[[21, 72, 67],
[23, 78, 62],
[32, 74, 56],
[73, 88, 67],
[32, 74, 56],
[43, 78, 69],
[32, 74, 54],
[52, 54, 76]],
columns=['a', 'b', 'c'])
#get first default number of rows
df1 = df.head()
#print the dataframe
print(df1)
1pandas as pd
2import pandas as pd
#initialize a dataframe
df = pd.DataFrame(
[[21, 72, 67],
[23, 78, 62],
[32, 74, 56],
[73, 88, 67],
[32, 74, 56],
[43, 78, 69],
[32, 74, 54],
[52, 54, 76]],
columns=['a', 'b', 'c'])
#get first default number of rows
df1 = df.head()
#print the dataframe
print(df1)
1pandas as pd
4import pandas as pd
#initialize a dataframe
df = pd.DataFrame(
[[21, 72, 67],
[23, 78, 62],
[32, 74, 56],
[73, 88, 67],
[32, 74, 56],
[43, 78, 69],
[32, 74, 54],
[52, 54, 76]],
columns=['a', 'b', 'c'])
#get first default number of rows
df1 = df.head()
#print the dataframe
print(df1)
1pandas as pd
6pandas as pd
7pandas as pd
8=
dict
0dict
dict
2
dict
3dict
4
Đầu ra: & nbsp; & nbsp;
Phương pháp 1: Sử dụng phương pháp dict
5. Sử dụng pandas.dataframe.head (n) để có được n hàng đầu tiên của dataFrame. Phải mất một đối số tùy chọn n (số lượng hàng bạn muốn nhận được từ đầu). Theo mặc định n = 5, nó trả về 5 hàng đầu tiên nếu giá trị của n không được truyền vào phương thức.Using dict
5 method. Use pandas.DataFrame.head(n) to get the first n rows of the DataFrame. It takes one optional argument n (number of rows you want to get from the start). By default n
= 5, it return first 5 rows if value of n is not passed to the method.
dict
6=
dict
8dict
9dict
2
dict
3=
2
Đầu ra: & nbsp; & nbsp;
Phương pháp 1: Sử dụng phương pháp dict
5. Sử dụng pandas.dataframe.head (n) để có được n hàng đầu tiên của dataFrame. Phải mất một đối số tùy chọn n (số lượng hàng bạn muốn nhận được từ đầu). Theo mặc định n = 5, nó trả về 5 hàng đầu tiên nếu giá trị của n không được truyền vào phương thức.Using =
3. Use
pandas.DataFrame.iloc() to get the first n rows. It is similar to the list slicing.
dict
6=
dict
8dict
9dict
2
dict
3=
2
Phương pháp 2: Sử dụng =
3. Sử dụng pandas.dataframe.iloc () để có được n hàng đầu tiên. Nó tương tự như việc cắt danh sách.
dict
6=
=
6dict
9=
8Display first n records of specific columns
Đầu ra:
dict
3'Name'
1
Đầu ra: & nbsp; & nbsp;
Phương pháp 1: Sử dụng phương pháp dict
5. Sử dụng pandas.dataframe.head (n) để có được n hàng đầu tiên của dataFrame. Phải mất một đối số tùy chọn n (số lượng hàng bạn muốn nhận được từ đầu). Theo mặc định n = 5, nó trả về 5 hàng đầu tiên nếu giá trị của n không được truyền vào phương thức.Display first n records from last n columns. Display first n records for the last n
columns using =
3
dict
6=
dict
8dict
9dict
2
dict
3: [
2
Phương pháp 2: Sử dụng =
3. Sử dụng pandas.dataframe.iloc () để có được n hàng đầu tiên. Nó tương tự như việc cắt danh sách.
Để có được 5 hàng đầu tiên của DataFrame, bạn có thể sử dụng phương thức dataFrame.head ().Lưu ý: DataFrame.đầu () Phương thức chức năng bằng cách trả về 5 hàng DataFrame đầu tiên theo mặc định.use the DataFrame. head() method. Note: The DataFrame. head() method functions by returning the first 5 rows of DataFrame by default.
Chọn n hàng đầu tiên từ hàm dataFrame bằng hàm đầu () trong mô -đun pandas của Python, lớp DataFrame cung cấp hàm Head () để tìm nạp các hàng trên cùng từ DataFrame, tức là nó trả về n hàng đầu tiên từ DataFrame.Nếu N không được cung cấp thì giá trị mặc định là 5.head() function
In Python's Pandas module, the Dataframe class provides a head() function to fetch top rows from a Dataframe i.e. It returns the first n rows from a dataframe. If n is not provided then default value is 5.
đầu () hàm.Để trả về 10 hàng đầu tiên, chúng ta có thể sử dụng dataFrame.head ().Phương pháp này được sử dụng để trả về 10 hàng của một DataFrame hoặc Sê -ri nhất định.DataFrame. head(). This method is used to return 10 rows of a given DataFrame or series.