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

Show

    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:   
     

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

    # .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:   
     

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

    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:   
     

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

    # 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:   
     

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


    TAM GIÁC

    NY

    • .loc
    • .iloc
    • .ix

    In [3]:

    url = 'http://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 gian
    0IthacaNanTAM GIÁCNY6/1/1930 22:00
    1WillingboroNanTAM GIÁCNY6/1/1930 22:00
    2TAM 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 gian
    0IthacaNanTAM GIÁCNY6/1/1930 22:00
    1WillingboroNanTAM GIÁCNY6/1/1930 22:00
    2TAM 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 gian
    0IthacaNanTAM GIÁCNY6/1/1930 22:00
    1WillingboroNanTAM GIÁCNY6/1/1930 22:00
    2TAM 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 bang
    0IthacaNanTAM GIÁCNY
    1WillingboroNanTAM GIÁCNY
    2TAM GIÁCNanTAM GIÁCNY
    36/1/1930 22:00NanTAM GIÁCNY
    46/1/1930 22:00NanTAM GIÁCNY
    56/1/1930 22:00NanTAM GIÁCNY
    66/1/1930 22:00NanTAM GIÁCNY
    76/1/1930 22:00NanTAM GIÁCNY
    86/1/1930 22:00NanWillingboroKHÁC
    9NJNan6/30/1930 20:00.IX sử dụng nhãn trộn và số nguyên khi sử dụng lựa chọn.
    10lục địaNanTAM GIÁCNY
    116/1/1930 22:00NanWillingboroKHÁC
    12NJ6/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
    13quốc giaNanTAM GIÁCIa
    14NYNanTAM GIÁCNY
    156/1/1930 22:00NanTAM GIÁCNY
    166/1/1930 22:00NanNanNY
    176/1/1930 22:00NanNanWillingboro
    18KHÁCNanNJ6/30/1930 20:00
    19.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
    20NJNanTAM GIÁCNY
    21NanNanNan6/1/1930 22:00
    22NanNanTAM GIÁC6/1/1930 22:00
    23WillingboroNanNJ6/30/1930 20:00
    24.IX sử dụng nhãn trộn và số nguyên khi sử dụng lựa chọn.NanTAM GIÁCNY
    256/1/1930 22:00NanWillingboroNY
    26.IX sử dụng nhãn trộn và số nguyên khi sử dụng lựa chọn.NanTAM GIÁCNY
    276/1/1930 22:00NanTAM GIÁCNY
    286/1/1930 22:00NanTAM GIÁCNY
    296/1/1930 22:00NanTAM GIÁCNY
    6/1/1930 22:00WillingboroWillingboroWillingboroWillingboro
    18211TAM GIÁCNanNY6/1/1930 22:00
    18212WillingboroNanTAM GIÁCNY
    182136/1/1930 22:00WillingboroWillingboroNY
    182146/1/1930 22:00NanWillingboroKHÁC
    18215NJNanTAM GIÁCKHÁC
    18216NJ6/30/1930 20:00TAM GIÁCNY
    182176/1/1930 22:00NanTAM GIÁCNY
    182186/1/1930 22:00NanNYKHÁC
    18219NJNan6/30/1930 20:00NY
    182206/1/1930 22:00WillingboroTAM GIÁCNY
    182216/1/1930 22:00NanTAM GIÁCNY
    182226/1/1930 22:00NanTAM GIÁCWillingboro
    18223KHÁCNanNanlục địa
    18224quốc giaNanTAM GIÁCNY
    182256/1/1930 22:00NanWillingboroNY
    182266/1/1930 22:00NanWillingboroNY
    182276/1/1930 22:00NanTAM GIÁCNY
    182286/1/1930 22:00NanTAM GIÁCKHÁC
    18229NJNanTAM GIÁCNY
    182306/1/1930 22:00NanTAM GIÁCNY
    182316/1/1930 22:00NanTAM GIÁCNY
    182326/1/1930 22:00NanNanWI
    18233Willingboro6/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
    18234NJNanTAM GIÁCNY
    182356/1/1930 22:00NanNanWillingboro
    18236KHÁCNanTAM GIÁCNY
    182376/1/1930 22:00NanTAM GIÁCIa
    18238Sông đại bàngNanNanWI
    18239Sông đại bàng6/30/1930 20:00TAM GIÁCWI
    18240YborNanTAM 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 bang
    0IthacaNanTAM GIÁCNY
    1WillingboroNanTAM GIÁCNY
    2TAM 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 gian
    16946/1/1930 22:00NanWillingboroNY6/1/1930 22:00
    21446/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    46866/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    72936/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    84886/1/1930 22:00NanNanNY6/1/1930 22:00
    87686/1/1930 22:00NanNanNY6/1/1930 22:00
    108166/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
    109486/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    110456/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    123226/1/1930 22:00NanWillingboroNY6/1/1930 22:00
    129416/1/1930 22:00Nan6/30/1930 20:00NY6/1/1930 22:00
    168036/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    173226/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 gian
    16946/1/1930 22:00NanWillingboroNY6/1/1930 22:00
    21446/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    46866/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    72936/1/1930 22:00NanTAM GIÁCNY6/1/1930 22:00
    84886/1/1930 22:00NanNanNY6/1/1930 22:00
    87686/1/1930 22:00NanNanNY6/1/1930 22:00
    108166/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
    109486/1/1930 22:00NanTAM GIÁCCa.14/11/1997 19:55
    11045OaklandNanTAM GIÁCCa.12/10/1997 1:30
    12322OaklandNanTAM GIÁCCa.12/10/1997 1:30
    12941OaklandNanTAM GIÁCCa.12/10/1997 1:30
    16803OaklandNanTAM GIÁC12/10/1997 1:30QUẢ CẦU LỬA
    17322OaklandNanTAM 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:40
    0HÌNH TRỤ1/23/1999 21:30
    1Md7/4/2000 23:00
    29/1/2000 21:35Thành phố
    3Tiểu bangIthaca
    4NY1/23/1999 21:30
    5Md7/4/2000 23:00
    69/1/2000 21:35Ca.
    7Thành phốTiểu bang
    8IthacaNY
    9WillingboroNJ
    10HolyokeCa.
    11ĐồngAbilene
    12KSHội chợ Thế giới New York
    13Thành phố thung lũngThứ nd
    14Hồ miệng núi lửaTiểu bang
    15IthacaCa.
    16NYCa.
    17WillingboroNJ
    18HolyokeĐồng
    19AbileneNY
    20WillingboroNJ
    21NanTAM GIÁC
    22NanTAM GIÁC
    2312/10/1997 1:30QUẢ CẦU LỬA
    2410/9/1998 19:40HÌNH TRỤ
    251/23/1999 21:30Ca.
    2610/9/1998 19:40HÌNH TRỤ
    271/23/1999 21:30Md
    287/4/2000 23:00Md
    297/4/2000 23:009/1/2000 21:35
    Thành phốTiểu bangTiểu bang
    182119/1/2000 21:35Thành phố
    18212Tiểu bangCa.
    18213IthacaCa.
    18214NYWillingboro
    18215NJWillingboro
    18216NJCa.
    18217HolyokeThành phố
    18218Tiểu bangWillingboro
    18219NJCa.
    18220HolyokeCa.
    18221ĐồngAbilene
    18222KSHội chợ Thế giới New York
    18223Thành phố thung lũngHội chợ Thế giới New York
    18224Thành phố thung lũngThứ nd
    18225Hồ miệng núi lửaCa.
    18226AlmaCa.
    18227AlmaCa.
    18228MiWillingboro
    18229NJHolyoke
    18230ĐồngCa.
    18231ĐồngCa.
    18232AbileneKS
    18233Hội chợ Thế giới New YorkNY
    18234WillingboroCa.
    18235NJHolyoke
    18236ĐồngHolyoke
    18237ĐồngThứ nd
    18238Hồ miệng núi lửaKS
    18239Hồ miệng núi lửaKS
    18240Hộ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:40
    0HÌNH TRỤNanTAM GIÁC1/23/1999 21:30
    1MdNanTAM GIÁC7/4/2000 23:00
    29/1/2000 21:35NanTAM GIÁCThành phố
    3Tiểu bangNanTAM GIÁCIthaca
    4NYNanTAM GIÁC1/23/1999 21:30
    5MdNanTAM GIÁC7/4/2000 23:00
    69/1/2000 21:35NanTAM GIÁCCa.
    7Thành phốNanTAM GIÁCTiểu bang
    8IthacaNanTAM GIÁCNY
    9WillingboroNanTAM GIÁCNJ
    10HolyokeNanTAM GIÁCCa.
    11ĐồngNanTAM GIÁCAbilene
    12KSHội chợ Thế giới New YorkThành phố thung lũngHội chợ Thế giới New York
    13Thành phố thung lũngNanTAM GIÁCThứ nd
    14Hồ miệng núi lửaNanTAM GIÁCTiểu bang
    15IthacaNanTAM GIÁCCa.
    16NYNanNanCa.
    17WillingboroNanNanNJ
    18HolyokeNanTAM GIÁCĐồng
    19AbileneHội chợ Thế giới New YorkTAM GIÁCNY
    20WillingboroNanTAM GIÁCNJ
    21NanNanNanTAM GIÁC
    22NanNanTAM GIÁCTAM GIÁC
    2312/10/1997 1:30NanTAM GIÁCQUẢ CẦU LỬA
    2410/9/1998 19:40NanTAM GIÁCHÌNH TRỤ
    251/23/1999 21:30NanTAM GIÁCCa.
    2610/9/1998 19:40NanTAM GIÁCHÌNH TRỤ
    271/23/1999 21:30NanTAM GIÁCMd
    287/4/2000 23:00NanTAM GIÁCMd
    297/4/2000 23:00NanTAM GIÁC9/1/2000 21:35
    Thành phốTiểu bangTiểu bangTiểu bangTiểu bang
    182119/1/2000 21:35NanThành phốThành phố
    18212Tiểu bangNanTAM GIÁCCa.
    18213IthacaNYTAM GIÁCCa.
    18214NYNanTAM GIÁCWillingboro
    18215NJNanTAM GIÁCWillingboro
    18216NJHolyokeTAM GIÁCCa.
    18217HolyokeNanTAM GIÁCThành phố
    18218Tiểu bangNanThành phốWillingboro
    18219NJNanHolyokeCa.
    18220HolyokeĐồngTAM GIÁCCa.
    18221ĐồngNanTAM GIÁCAbilene
    18222KSNanTAM GIÁCHội chợ Thế giới New York
    18223Thành phố thung lũngNanNanHội chợ Thế giới New York
    18224Thành phố thung lũngNanTAM GIÁCThứ nd
    18225Hồ miệng núi lửaNanTAM GIÁCCa.
    18226AlmaNanTAM GIÁCCa.
    18227AlmaNanTAM GIÁCCa.
    18228MiNanTAM GIÁCWillingboro
    18229NJNanTAM GIÁCHolyoke
    18230ĐồngNanTAM GIÁCCa.
    18231ĐồngNanTAM GIÁCCa.
    18232AbileneNanNanKS
    18233Hội chợ Thế giới New YorkHội chợ Thế giới New YorkThành phố thung lũngNY
    18234WillingboroNanTAM GIÁCCa.
    18235NJNanNanHolyoke
    18236ĐồngNanTAM GIÁCHolyoke
    18237ĐồngNanTAM GIÁCThứ nd
    18238Hồ miệng núi lửaNanNanKS
    18239Hồ miệng núi lửaHội chợ Thế giới New YorkTAM GIÁCKS
    18240Hộ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Ụ
    0HÌNH TRỤNanTAM GIÁC1/23/1999 21:30Md
    1MdNanTAM GIÁC7/4/2000 23:009/1/2000 21:35
    29/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:40
    0HÌNH TRỤ1/23/1999 21:30
    1Md7/4/2000 23:00
    29/1/2000 21:35Thành phố
    3Tiểu bangIthaca
    4NY1/23/1999 21:30
    5Md7/4/2000 23:00
    69/1/2000 21:35Ca.
    7Thành phốTiểu bang
    8IthacaNY
    9WillingboroNJ
    10HolyokeCa.
    11ĐồngAbilene
    12KSHội chợ Thế giới New York
    13Thành phố thung lũngThứ nd
    14Hồ miệng núi lửaTiểu bang
    15IthacaCa.
    16NYCa.
    17WillingboroNJ
    18HolyokeĐồng
    19AbileneNY
    20WillingboroNJ
    21NanTAM GIÁC
    22NanTAM GIÁC
    2312/10/1997 1:30QUẢ CẦU LỬA
    2410/9/1998 19:40HÌNH TRỤ
    251/23/1999 21:30Ca.
    2610/9/1998 19:40HÌNH TRỤ
    271/23/1999 21:30Md
    287/4/2000 23:00Md
    297/4/2000 23:009/1/2000 21:35
    Thành phốTiểu bangTiểu bang
    182119/1/2000 21:35Thành phố
    18212Tiểu bangCa.
    18213IthacaCa.
    18214NYWillingboro
    18215NJWillingboro
    18216NJCa.
    18217HolyokeThành phố
    18218Tiểu bangWillingboro
    18219NJCa.
    18220HolyokeCa.
    18221ĐồngAbilene
    18222KSHội chợ Thế giới New York
    18223Thành phố thung lũngHội chợ Thế giới New York
    18224Thành phố thung lũngThứ nd
    18225Hồ miệng núi lửaCa.
    18226AlmaCa.
    18227AlmaCa.
    18228MiWillingboro
    18229NJHolyoke
    18230ĐồngCa.
    18231ĐồngCa.
    18232AbileneKS
    18233Hội chợ Thế giới New YorkNY
    18234WillingboroCa.
    18235NJHolyoke
    18236ĐồngHolyoke
    18237ĐồngThứ nd
    18238Hồ miệng núi lửaKS
    18239Hồ miệng núi lửaKS
    18240Hộ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Ụ
    0HÌNH TRỤNanTAM GIÁC1/23/1999 21:30Md
    1MdNanTAM 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 địa
    quốc gia
    Afghanistan0 0 0 0.0 Châu Á
    Albania89 132 54 4.9 Châu Âu
    Algeria25 0 14 0.7 Châu phi
    Andorra245 138 312 12.4 Châu Âu
    Algeria217 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_servings
    quốc gia
    Albania89 132
    Algeria25 0
    Andorra245 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ố
    0Màu sắc được báo cáoIthaca
    1NanIthaca
    2NanIthaca