Hướng dẫn how to separate rows in python - cách tách hàng trong python

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Cải thiện bài viết

    Lưu bài viết

    Đọc
     

    Python3

    Bàn luận

    Chúng ta có thể thử các cách tiếp cận khác nhau để chia dữ liệu để có được kết quả mong muốn. Hãy cùng lấy một ví dụ về một bộ dữ liệu kim cương. & Nbsp; & nbsp;

    # .loc DataFrame method
    # filtering rows and selecting columns by label
    
    # format
    # ufo.loc[rows, columns]
    
    # row 0, all columns
    ufo.loc[0, :]
    
    4
    # .loc DataFrame method
    # filtering rows and selecting columns by label
    
    # format
    # ufo.loc[rows, columns]
    
    # row 0, all columns
    ufo.loc[0, :]
    
    5

    # .loc DataFrame method
    # filtering rows and selecting columns by label
    
    # format
    # ufo.loc[rows, columns]
    
    # row 0, all columns
    ufo.loc[0, :]
    
    4
    # .loc DataFrame method
    # filtering rows and selecting columns by label
    
    # format
    # ufo.loc[rows, columns]
    
    # row 0, all columns
    ufo.loc[0, :]
    
    7

    City                       Ithaca
    Colors Reported               NaN
    Shape Reported           TRIANGLE
    State                          NY
    Time               6/1/1930 22:00
    Name: 0, dtype: object
    5

    Output:   
     

    # .loc DataFrame method
    # filtering rows and selecting columns by label
    
    # format
    # ufo.loc[rows, columns]
    
    # row 0, all columns
    ufo.loc[0, :]
    
    4
    # .loc DataFrame method
    # filtering rows and selecting columns by label
    
    # format
    # ufo.loc[rows, columns]
    
    # row 0, all columns
    ufo.loc[0, :]
    
    9

    In the below code, the dataframe is divided into two parts, first 1000 rows, and remaining rows. We can see the shape of the newly formed dataframes as the output of the given code.
     

    Python3

    City                       Ithaca
    Colors Reported               NaN
    Shape Reported           TRIANGLE
    State                          NY
    Time               6/1/1930 22:00
    Name: 0, dtype: object
    0
    City                       Ithaca
    Colors Reported               NaN
    Shape Reported           TRIANGLE
    State                          NY
    Time               6/1/1930 22:00
    Name: 0, dtype: object
    1
    City                       Ithaca
    Colors Reported               NaN
    Shape Reported           TRIANGLE
    State                          NY
    Time               6/1/1930 22:00
    Name: 0, dtype: object
    2
    City                       Ithaca
    Colors Reported               NaN
    Shape Reported           TRIANGLE
    State                          NY
    Time               6/1/1930 22:00
    Name: 0, dtype: object
    3
    City                       Ithaca
    Colors Reported               NaN
    Shape Reported           TRIANGLE
    State                          NY
    Time               6/1/1930 22:00
    Name: 0, dtype: object
    4

    Phương pháp 1: Tách gấu trúc DataFrame theo lệnh Row Inin Mã dưới đây, DataFrame được chia thành hai phần, 1000 hàng đầu tiên và các hàng còn lại. Chúng ta có thể thấy hình dạng của các khung dữ liệu mới được hình thành là đầu ra của mã đã cho. & NBSP;

    # rows 0, 1, 2
    # all columns
    
    ufo.loc[[0, 1, 2], :]
    
    # more efficient code
    ufo.loc[0:2, :]
    
    6
    # rows 0, 1, 2
    # all columns
    
    ufo.loc[[0, 1, 2], :]
    
    # more efficient code
    ufo.loc[0:2, :]
    
    7
    # rows 0, 1, 2
    # all columns
    
    ufo.loc[[0, 1, 2], :]
    
    # more efficient code
    ufo.loc[0:2, :]
    
    8
    # rows 0, 1, 2
    # all columns
    
    ufo.loc[[0, 1, 2], :]
    
    # more efficient code
    ufo.loc[0:2, :]
    
    9
    # if you leave off ", :" pandas would assume it's there
    # but you should leave it there to improve code readability
    ufo.loc[0:2]
    
    0
    # if you leave off ", :" pandas would assume it's there
    # but you should leave it there to improve code readability
    ufo.loc[0:2]
    
    1

    Output:   
     

    City                       Ithaca
    Colors Reported               NaN
    Shape Reported           TRIANGLE
    State                          NY
    Time               6/1/1930 22:00
    Name: 0, dtype: object
    6
    City                       Ithaca
    Colors Reported               NaN
    Shape Reported           TRIANGLE
    State                          NY
    Time               6/1/1930 22:00
    Name: 0, dtype: object
    1
    City                       Ithaca
    Colors Reported               NaN
    Shape Reported           TRIANGLE
    State                          NY
    Time               6/1/1930 22:00
    Name: 0, dtype: object
    8
    City                       Ithaca
    Colors Reported               NaN
    Shape Reported           TRIANGLE
    State                          NY
    Time               6/1/1930 22:00
    Name: 0, dtype: object
    9
    # rows 0, 1, 2
    # all columns
    
    ufo.loc[[0, 1, 2], :]
    
    # more efficient code
    ufo.loc[0:2, :]
    
    0

    Here, we will first grouped the data by column value “color”. The newly formed dataframe consists of grouped data with color = “E”.
     

    Python3

    # rows 0, 1, 2
    # all columns
    
    ufo.loc[[0, 1, 2], :]
    
    # more efficient code
    ufo.loc[0:2, :]
    
    1
    City                       Ithaca
    Colors Reported               NaN
    Shape Reported           TRIANGLE
    State                          NY
    Time               6/1/1930 22:00
    Name: 0, dtype: object
    1
    # rows 0, 1, 2
    # all columns
    
    ufo.loc[[0, 1, 2], :]
    
    # more efficient code
    ufo.loc[0:2, :]
    
    3
    City                       Ithaca
    Colors Reported               NaN
    Shape Reported           TRIANGLE
    State                          NY
    Time               6/1/1930 22:00
    Name: 0, dtype: object
    9
    # rows 0, 1, 2
    # all columns
    
    ufo.loc[[0, 1, 2], :]
    
    # more efficient code
    ufo.loc[0:2, :]
    
    5

    Phương pháp 2: Tách dữ liệu gấu trúc theo các nhóm được hình thành từ Valueshere cột duy nhất, trước tiên chúng tôi sẽ nhóm dữ liệu theo giá trị cột. DataFrame mới được hình thành bao gồm dữ liệu được nhóm với Color = Hồi E Tiết. & NBSP;

    # all rows
    # column: City
    ufo.loc[:, 'City']
    
    0

    Output:   
     

    # if you leave off ", :" pandas would assume it's there
    # but you should leave it there to improve code readability
    ufo.loc[0:2]
    
    2
    City                       Ithaca
    Colors Reported               NaN
    Shape Reported           TRIANGLE
    State                          NY
    Time               6/1/1930 22:00
    Name: 0, dtype: object
    1
    # if you leave off ", :" pandas would assume it's there
    # but you should leave it there to improve code readability
    ufo.loc[0:2]
    
    4

    In the above code, we can see that we have formed a new dataset of a size of 0.6 i.e. 60% of total rows [or length of the dataset], which now consists of 32364 rows. These rows are selected randomly. 
     

    Python3

    # if you leave off ", :" pandas would assume it's there
    # but you should leave it there to improve code readability
    ufo.loc[0:2]
    
    5
    City                       Ithaca
    Colors Reported               NaN
    Shape Reported           TRIANGLE
    State                          NY
    Time               6/1/1930 22:00
    Name: 0, dtype: object
    1
    # if you leave off ", :" pandas would assume it's there
    # but you should leave it there to improve code readability
    ufo.loc[0:2]
    
    7
    # if you leave off ", :" pandas would assume it's there
    # but you should leave it there to improve code readability
    ufo.loc[0:2]
    
    8
    City                       Ithaca
    Colors Reported               NaN
    Shape Reported           TRIANGLE
    State                          NY
    Time               6/1/1930 22:00
    Name: 0, dtype: object
    4

    0                      Ithaca
    1                 Willingboro
    2                     Holyoke
    3                     Abilene
    4        New York Worlds Fair
    5                 Valley City
    6                 Crater Lake
    7                        Alma
    8                     Eklutna
    9                     Hubbard
    10                    Fontana
    11                   Waterloo
    12                     Belton
    13                     Keokuk
    14                  Ludington
    15                Forest Home
    16                Los Angeles
    17                  Hapeville
    18                     Oneida
    19                 Bering Sea
    20                   Nebraska
    21                        NaN
    22                        NaN
    23                  Owensboro
    24                 Wilderness
    25                  San Diego
    26                 Wilderness
    27                     Clovis
    28                 Los Alamos
    29               Ft. Duschene
                     ...         
    18211                 Holyoke
    18212                  Carson
    18213                Pasadena
    18214                  Austin
    18215                El Campo
    18216            Garden Grove
    18217           Berthoud Pass
    18218              Sisterdale
    18219            Garden Grove
    18220             Shasta Lake
    18221                Franklin
    18222          Albrightsville
    18223              Greenville
    18224                 Eufaula
    18225             Simi Valley
    18226           San Francisco
    18227           San Francisco
    18228              Kingsville
    18229                 Chicago
    18230             Pismo Beach
    18231             Pismo Beach
    18232                    Lodi
    18233               Anchorage
    18234                Capitola
    18235          Fountain Hills
    18236              Grant Park
    18237             Spirit Lake
    18238             Eagle River
    18239             Eagle River
    18240                    Ybor
    Name: City, dtype: object
    0

    Output:   
     


    TAM GIÁC

    NY

    • .loc
    • .iloc
    • .ix

    In [3]:

    url = '//bit.ly/uforeports'
    ufo = pd.read_csv[url]
    

    In [5]:

    # show first 3 shows
    ufo.head[3]
    

    Out[5]:

    Thành phốMàu sắc được báo cáoHình dạng báo cáoTiểu bangThời gian012
    IthacaNanTAM GIÁCNY6/1/1930 22:00
    WillingboroNanTAM GIÁCNY6/1/1930 22:00
    TAM GIÁCNanTAM GIÁCNY6/1/1930 22:00

    Willingboro
    This is a really powerful and flexible method

    In [6]:

    # .loc DataFrame method
    # filtering rows and selecting columns by label
    
    # format
    # ufo.loc[rows, columns]
    
    # row 0, all columns
    ufo.loc[0, :]
    

    Out[6]:

    City                       Ithaca
    Colors Reported               NaN
    Shape Reported           TRIANGLE
    State                          NY
    Time               6/1/1930 22:00
    Name: 0, dtype: object

    In [10]:

    # rows 0, 1, 2
    # all columns
    
    ufo.loc[[0, 1, 2], :]
    
    # more efficient code
    ufo.loc[0:2, :]
    

    Out[10]:

    Thành phốMàu sắc được báo cáoHình dạng báo cáoTiểu bangThời gian012
    IthacaNanTAM GIÁCNY6/1/1930 22:00
    WillingboroNanTAM GIÁCNY6/1/1930 22:00
    TAM GIÁCNanTAM GIÁCNY6/1/1930 22:00

    In [12]:

    # if you leave off ", :" pandas would assume it's there
    # but you should leave it there to improve code readability
    ufo.loc[0:2]
    

    Out[12]:

    Thành phốMàu sắc được báo cáoHình dạng báo cáoTiểu bangThời gian012
    IthacaNanTAM GIÁCNY6/1/1930 22:00
    WillingboroNanTAM GIÁCNY6/1/1930 22:00
    TAM GIÁCNanTAM GIÁCNY6/1/1930 22:00

    In [13]:

    # all rows
    # column: City
    ufo.loc[:, 'City']
    

    Out[13]:

    0                      Ithaca
    1                 Willingboro
    2                     Holyoke
    3                     Abilene
    4        New York Worlds Fair
    5                 Valley City
    6                 Crater Lake
    7                        Alma
    8                     Eklutna
    9                     Hubbard
    10                    Fontana
    11                   Waterloo
    12                     Belton
    13                     Keokuk
    14                  Ludington
    15                Forest Home
    16                Los Angeles
    17                  Hapeville
    18                     Oneida
    19                 Bering Sea
    20                   Nebraska
    21                        NaN
    22                        NaN
    23                  Owensboro
    24                 Wilderness
    25                  San Diego
    26                 Wilderness
    27                     Clovis
    28                 Los Alamos
    29               Ft. Duschene
                     ...         
    18211                 Holyoke
    18212                  Carson
    18213                Pasadena
    18214                  Austin
    18215                El Campo
    18216            Garden Grove
    18217           Berthoud Pass
    18218              Sisterdale
    18219            Garden Grove
    18220             Shasta Lake
    18221                Franklin
    18222          Albrightsville
    18223              Greenville
    18224                 Eufaula
    18225             Simi Valley
    18226           San Francisco
    18227           San Francisco
    18228              Kingsville
    18229                 Chicago
    18230             Pismo Beach
    18231             Pismo Beach
    18232                    Lodi
    18233               Anchorage
    18234                Capitola
    18235          Fountain Hills
    18236              Grant Park
    18237             Spirit Lake
    18238             Eagle River
    18239             Eagle River
    18240                    Ybor
    Name: City, dtype: object

    In [15]:

    # all rows
    # column: City, State
    ufo.loc[:, ['City', 'State']]
    
    # similar code for City through State
    ufo.loc[:, 'City':'State']
    

    Out[15]:

    Thành phốMàu sắc được báo cáoHình dạng báo cáoTiểu bang012345678910111213141516171819202122232425262728296/1/1930 22:00182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240
    IthacaNanTAM GIÁCNY
    WillingboroNanTAM GIÁCNY
    TAM GIÁCNanTAM GIÁCNY
    6/1/1930 22:00NanTAM GIÁCNY
    6/1/1930 22:00NanTAM GIÁCNY
    6/1/1930 22:00NanTAM GIÁCNY
    6/1/1930 22:00NanTAM GIÁCNY
    6/1/1930 22:00NanTAM GIÁCNY
    6/1/1930 22:00NanWillingboroKHÁC
    NJNan6/30/1930 20:00.IX sử dụng nhãn trộn và số nguyên khi sử dụng lựa chọn.
    lục địaNanTAM GIÁCNY
    6/1/1930 22:00NanWillingboroKHÁC
    NJ6/30/1930 20:00.IX sử dụng nhãn trộn và số nguyên khi sử dụng lựa chọn.lục địa
    quốc giaNanTAM GIÁCIa
    NYNanTAM GIÁCNY
    6/1/1930 22:00NanTAM GIÁCNY
    6/1/1930 22:00NanNanNY
    6/1/1930 22:00NanNanWillingboro
    KHÁCNanNJ6/30/1930 20:00
    .IX sử dụng nhãn trộn và số nguyên khi sử dụng lựa chọn.6/30/1930 20:00TAM GIÁCKHÁC
    NJNanTAM GIÁCNY
    NanNanNan6/1/1930 22:00
    NanNanTAM GIÁC6/1/1930 22:00
    WillingboroNanNJ6/30/1930 20:00
    .IX sử dụng nhãn trộn và số nguyên khi sử dụng lựa chọn.NanTAM GIÁCNY
    6/1/1930 22:00NanWillingboroNY
    .IX sử dụng nhãn trộn và số nguyên khi sử dụng lựa chọn.NanTAM GIÁCNY
    6/1/1930 22:00NanTAM GIÁCNY
    6/1/1930 22:00NanTAM GIÁCNY
    6/1/1930 22:00NanTAM GIÁCNY
    WillingboroWillingboroWillingboroWillingboro
    TAM GIÁCNanNY6/1/1930 22:00
    WillingboroNanTAM GIÁCNY
    6/1/1930 22:00WillingboroWillingboroNY
    6/1/1930 22:00NanWillingboroKHÁC
    NJNanTAM GIÁCKHÁC
    NJ6/30/1930 20:00TAM GIÁCNY
    6/1/1930 22:00NanTAM GIÁCNY
    6/1/1930 22:00NanNYKHÁC
    NJNan6/30/1930 20:00NY
    6/1/1930 22:00WillingboroTAM GIÁCNY
    6/1/1930 22:00NanTAM GIÁCNY
    6/1/1930 22:00NanTAM GIÁCWillingboro
    KHÁCNanNanlục địa
    quốc giaNanTAM GIÁCNY
    6/1/1930 22:00NanWillingboroNY
    6/1/1930 22:00NanWillingboroNY
    6/1/1930 22:00NanTAM GIÁCNY
    6/1/1930 22:00NanTAM GIÁCKHÁC
    NJNanTAM GIÁCNY
    6/1/1930 22:00NanTAM GIÁCNY
    6/1/1930 22:00NanTAM GIÁCNY
    6/1/1930 22:00NanNanWI
    Willingboro6/30/1930 20:00.IX sử dụng nhãn trộn và số nguyên khi sử dụng lựa chọn.KHÁC
    NJNanTAM GIÁCNY
    6/1/1930 22:00NanNanWillingboro
    KHÁCNanTAM GIÁCNY
    6/1/1930 22:00NanTAM GIÁCIa
    Sông đại bàngNanNanWI
    Sông đại bàng6/30/1930 20:00TAM GIÁCWI
    YborNanTAM GIÁCFl

    NY

    In [17]:

    # multiple rows and multiple columns
    ufo.loc[0:2, 'City':'State']
    

    Out[17]:

    Thành phốMàu sắc được báo cáoHình dạng báo cáoTiểu bang012
    IthacaNanTAM GIÁCNY
    WillingboroNanTAM GIÁCNY
    TAM GIÁCNanTAM GIÁCNY

    In [18]:

    # show first 3 shows
    ufo.head[3]
    
    0

    Out[18]:

    Thành phốMàu sắc được báo cáoHình dạng báo cáoTiểu bangThời gian16942144468672938488876810816109481104512322129411680317322
    6/1/1930 22:00NanWillingboroNY6/1/1930 22:00
    6/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    6/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    6/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    6/1/1930 22:00NanNanNY6/1/1930 22:00
    6/1/1930 22:00NanNanNY6/1/1930 22:00
    6/1/1930 22:00NanTAM GIÁC.IX sử dụng nhãn trộn và số nguyên khi sử dụng lựa chọn.lục địa
    6/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    6/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    6/1/1930 22:00NanWillingboroNY6/1/1930 22:00
    6/1/1930 22:00Nan6/30/1930 20:00NY6/1/1930 22:00
    6/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    6/1/1930 22:00Nan6/30/1930 20:00NY6/1/1930 22:00

    In [20]:

    # show first 3 shows
    ufo.head[3]
    
    1

    Out[20]:

    Thành phốMàu sắc được báo cáoHình dạng báo cáoTiểu bangThời gian16942144468672938488876810816109481104512322129411680317322
    6/1/1930 22:00NanWillingboroNY6/1/1930 22:00
    6/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    6/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    6/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    6/1/1930 22:00NanNanNY6/1/1930 22:00
    6/1/1930 22:00NanNanNY6/1/1930 22:00
    6/1/1930 22:00NanTAM GIÁC.IX sử dụng nhãn trộn và số nguyên khi sử dụng lựa chọn.lục địa
    6/1/1930 22:00NanTAM GIÁCCa.14/11/1997 19:55
    OaklandNanTAM GIÁCCa.12/10/1997 1:30
    OaklandNanTAM GIÁCCa.12/10/1997 1:30
    OaklandNanTAM GIÁCCa.12/10/1997 1:30
    OaklandNanTAM GIÁC12/10/1997 1:30QUẢ CẦU LỬA
    OaklandNanTAM GIÁCCa.12/10/1997 1:30

    In [21]:

    # show first 3 shows
    ufo.head[3]
    
    2

    Out[21]:

    # show first 3 shows
    ufo.head[3]
    
    3

    In [24]:

    # show first 3 shows
    ufo.head[3]
    
    4

    Out[24]:

    # show first 3 shows
    ufo.head[3]
    
    3

    Out[25]:

    QUẢ CẦU LỬA10/9/1998 19:4001234567891011121314151617181920212223242526272829Thành phố182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240
    HÌNH TRỤ1/23/1999 21:30
    Md7/4/2000 23:00
    9/1/2000 21:35Thành phố
    Tiểu bangIthaca
    NY1/23/1999 21:30
    Md7/4/2000 23:00
    9/1/2000 21:35Ca.
    Thành phốTiểu bang
    IthacaNY
    WillingboroNJ
    HolyokeCa.
    ĐồngAbilene
    KSHội chợ Thế giới New York
    Thành phố thung lũngThứ nd
    Hồ miệng núi lửaTiểu bang
    IthacaCa.
    NYCa.
    WillingboroNJ
    HolyokeĐồng
    AbileneNY
    WillingboroNJ
    NanTAM GIÁC
    NanTAM GIÁC
    12/10/1997 1:30QUẢ CẦU LỬA
    10/9/1998 19:40HÌNH TRỤ
    1/23/1999 21:30Ca.
    10/9/1998 19:40HÌNH TRỤ
    1/23/1999 21:30Md
    7/4/2000 23:00Md
    7/4/2000 23:009/1/2000 21:35
    Tiểu bangTiểu bang
    9/1/2000 21:35Thành phố
    Tiểu bangCa.
    IthacaCa.
    NYWillingboro
    NJWillingboro
    NJCa.
    HolyokeThành phố
    Tiểu bangWillingboro
    NJCa.
    HolyokeCa.
    ĐồngAbilene
    KSHội chợ Thế giới New York
    Thành phố thung lũngHội chợ Thế giới New York
    Thành phố thung lũngThứ nd
    Hồ miệng núi lửaCa.
    AlmaCa.
    AlmaCa.
    MiWillingboro
    NJHolyoke
    ĐồngCa.
    ĐồngCa.
    AbileneKS
    Hội chợ Thế giới New YorkNY
    WillingboroCa.
    NJHolyoke
    ĐồngHolyoke
    ĐồngThứ nd
    Hồ miệng núi lửaKS
    Hồ miệng núi lửaKS
    Hội chợ Thế giới New YorkThành phố thung lũng

    Thứ nd

    In [28]:

    # show first 3 shows
    ufo.head[3]
    
    6

    Out[28]:

    QUẢ CẦU LỬA10/9/1998 19:40HÌNH TRỤ10/9/1998 19:4001234567891011121314151617181920212223242526272829Thành phố182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240
    HÌNH TRỤNanTAM GIÁC1/23/1999 21:30
    MdNanTAM GIÁC7/4/2000 23:00
    9/1/2000 21:35NanTAM GIÁCThành phố
    Tiểu bangNanTAM GIÁCIthaca
    NYNanTAM GIÁC1/23/1999 21:30
    MdNanTAM GIÁC7/4/2000 23:00
    9/1/2000 21:35NanTAM GIÁCCa.
    Thành phốNanTAM GIÁCTiểu bang
    IthacaNanTAM GIÁCNY
    WillingboroNanTAM GIÁCNJ
    HolyokeNanTAM GIÁCCa.
    ĐồngNanTAM GIÁCAbilene
    KSHội chợ Thế giới New YorkThành phố thung lũngHội chợ Thế giới New York
    Thành phố thung lũngNanTAM GIÁCThứ nd
    Hồ miệng núi lửaNanTAM GIÁCTiểu bang
    IthacaNanTAM GIÁCCa.
    NYNanNanCa.
    WillingboroNanNanNJ
    HolyokeNanTAM GIÁCĐồng
    AbileneHội chợ Thế giới New YorkTAM GIÁCNY
    WillingboroNanTAM GIÁCNJ
    NanNanNanTAM GIÁC
    NanNanTAM GIÁCTAM GIÁC
    12/10/1997 1:30NanTAM GIÁCQUẢ CẦU LỬA
    10/9/1998 19:40NanTAM GIÁCHÌNH TRỤ
    1/23/1999 21:30NanTAM GIÁCCa.
    10/9/1998 19:40NanTAM GIÁCHÌNH TRỤ
    1/23/1999 21:30NanTAM GIÁCMd
    7/4/2000 23:00NanTAM GIÁCMd
    7/4/2000 23:00NanTAM GIÁC9/1/2000 21:35
    Tiểu bangTiểu bangTiểu bangTiểu bang
    9/1/2000 21:35NanThành phốThành phố
    Tiểu bangNanTAM GIÁCCa.
    IthacaNYTAM GIÁCCa.
    NYNanTAM GIÁCWillingboro
    NJNanTAM GIÁCWillingboro
    NJHolyokeTAM GIÁCCa.
    HolyokeNanTAM GIÁCThành phố
    Tiểu bangNanThành phốWillingboro
    NJNanHolyokeCa.
    HolyokeĐồngTAM GIÁCCa.
    ĐồngNanTAM GIÁCAbilene
    KSNanTAM GIÁCHội chợ Thế giới New York
    Thành phố thung lũngNanNanHội chợ Thế giới New York
    Thành phố thung lũngNanTAM GIÁCThứ nd
    Hồ miệng núi lửaNanTAM GIÁCCa.
    AlmaNanTAM GIÁCCa.
    AlmaNanTAM GIÁCCa.
    MiNanTAM GIÁCWillingboro
    NJNanTAM GIÁCHolyoke
    ĐồngNanTAM GIÁCCa.
    ĐồngNanTAM GIÁCCa.
    AbileneNanNanKS
    Hội chợ Thế giới New YorkHội chợ Thế giới New YorkThành phố thung lũngNY
    WillingboroNanTAM GIÁCCa.
    NJNanNanHolyoke
    ĐồngNanTAM GIÁCHolyoke
    ĐồngNanTAM GIÁCThứ nd
    Hồ miệng núi lửaNanNanKS
    Hồ miệng núi lửaHội chợ Thế giới New YorkTAM GIÁCKS
    Hội chợ Thế giới New YorkNanTAM GIÁCThành phố thung lũng

    Thứ nd

    In [31]:

    # show first 3 shows
    ufo.head[3]
    
    7

    Out[31]:

    QUẢ CẦU LỬA10/9/1998 19:40HÌNH TRỤ10/9/1998 19:40HÌNH TRỤ012
    HÌNH TRỤNanTAM GIÁC1/23/1999 21:30Md
    MdNanTAM GIÁC7/4/2000 23:009/1/2000 21:35
    9/1/2000 21:35NanTAM GIÁCThành phốTiểu bang

    In [38]:

    # show first 3 shows
    ufo.head[3]
    
    8

    Out[38]:

    QUẢ CẦU LỬA10/9/1998 19:4001234567891011121314151617181920212223242526272829Thành phố182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240
    HÌNH TRỤ1/23/1999 21:30
    Md7/4/2000 23:00
    9/1/2000 21:35Thành phố
    Tiểu bangIthaca
    NY1/23/1999 21:30
    Md7/4/2000 23:00
    9/1/2000 21:35Ca.
    Thành phốTiểu bang
    IthacaNY
    WillingboroNJ
    HolyokeCa.
    ĐồngAbilene
    KSHội chợ Thế giới New York
    Thành phố thung lũngThứ nd
    Hồ miệng núi lửaTiểu bang
    IthacaCa.
    NYCa.
    WillingboroNJ
    HolyokeĐồng
    AbileneNY
    WillingboroNJ
    NanTAM GIÁC
    NanTAM GIÁC
    12/10/1997 1:30QUẢ CẦU LỬA
    10/9/1998 19:40HÌNH TRỤ
    1/23/1999 21:30Ca.
    10/9/1998 19:40HÌNH TRỤ
    1/23/1999 21:30Md
    7/4/2000 23:00Md
    7/4/2000 23:009/1/2000 21:35
    Tiểu bangTiểu bang
    9/1/2000 21:35Thành phố
    Tiểu bangCa.
    IthacaCa.
    NYWillingboro
    NJWillingboro
    NJCa.
    HolyokeThành phố
    Tiểu bangWillingboro
    NJCa.
    HolyokeCa.
    ĐồngAbilene
    KSHội chợ Thế giới New York
    Thành phố thung lũngHội chợ Thế giới New York
    Thành phố thung lũngThứ nd
    Hồ miệng núi lửaCa.
    AlmaCa.
    AlmaCa.
    MiWillingboro
    NJHolyoke
    ĐồngCa.
    ĐồngCa.
    AbileneKS
    Hội chợ Thế giới New YorkNY
    WillingboroCa.
    NJHolyoke
    ĐồngHolyoke
    ĐồngThứ nd
    Hồ miệng núi lửaKS
    Hồ miệng núi lửaKS
    Hội chợ Thế giới New YorkThành phố thung lũng

    Thứ nd

    In [40]:

    # show first 3 shows
    ufo.head[3]
    
    9

    Out[40]:

    QUẢ CẦU LỬA10/9/1998 19:40HÌNH TRỤ10/9/1998 19:40HÌNH TRỤ01
    HÌNH TRỤNanTAM GIÁC1/23/1999 21:30Md
    MdNanTAM GIÁC7/4/2000 23:009/1/2000 21:35

    Thành phố
    Mix labels and integers when using selection.

    In [41]:

    # .loc DataFrame method
    # filtering rows and selecting columns by label
    
    # format
    # ufo.loc[rows, columns]
    
    # row 0, all columns
    ufo.loc[0, :]
    
    0

    Out[42]:

    beer_servingsspirit_servingswine_servingstotal_litres_of_pure_alcohollục địaquốc giaAfghanistanAlbaniaAlgeriaAndorraAlgeria
    0 0 0 0.0 Châu Á
    89 132 54 4.9 Châu Âu
    25 0 14 0.7 Châu phi
    245 138 312 12.4 Châu Âu
    217 57 45 5.9 Châu phi

    In [44]:

    # .loc DataFrame method
    # filtering rows and selecting columns by label
    
    # format
    # ufo.loc[rows, columns]
    
    # row 0, all columns
    ufo.loc[0, :]
    
    1

    In [46]:

    # .loc DataFrame method
    # filtering rows and selecting columns by label
    
    # format
    # ufo.loc[rows, columns]
    
    # row 0, all columns
    ufo.loc[0, :]
    
    2

    Out[46]:

    beer_servingsspirit_servingsquốc giaAlbaniaAlgeriaAndorra
    89 132
    25 0
    245 138

    In [48]:

    # .loc DataFrame method
    # filtering rows and selecting columns by label
    
    # format
    # ufo.loc[rows, columns]
    
    # row 0, all columns
    ufo.loc[0, :]
    
    3

    Out[48]:

    AngolaThành phố012
    Màu sắc được báo cáoIthaca
    NanIthaca
    NanIthaca

    Bài Viết Liên Quan

    Chủ Đề