Hướng dẫn how does python handle tabular data? - python xử lý dữ liệu dạng bảng như thế nào?

Tổng quan

Giảng dạy: 10 phút Bài tập: 10 phút 10 min
Exercises: 10 min

Show

Câu hỏi

  • Làm cách nào để đọc dữ liệu bảng?

Mục tiêu

  • Nhập thư viện Pandas.

  • Sử dụng gấu trúc để tải một bộ dữ liệu CSV đơn giản.

  • Nhận một số thông tin cơ bản về một khung dữ liệu gấu trúc.

Sử dụng thư viện PANDAS để thực hiện số liệu thống kê trên dữ liệu bảng.

  • Pandas là một thư viện Python được sử dụng rộng rãi cho số liệu thống kê, đặc biệt là trên dữ liệu bảng.
  • Ray nhiều tính năng từ các khung dữ liệu R.
    • Một bảng 2 chiều có các cột có tên và có khả năng có các loại dữ liệu khác nhau.
  • Tải nó với
           country  gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  \
    0    Australia     10039.59564     10949.64959     12217.22686
    1  New Zealand     10556.57566     12247.39532     13175.67800
    
       gdpPercap_1967  gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  \
    0     14526.12465     16788.62948     18334.19751     19477.00928
    1     14463.91893     16046.03728     16233.71770     17632.41040
    
       gdpPercap_1987  gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  \
    0     21888.88903     23424.76683     26997.93657     30687.75473
    1     19007.19129     18363.32494     21050.41377     23189.80135
    
       gdpPercap_2007
    0     34435.36744
    1     25185.00911
    
    8. Bí danh PD thường được sử dụng cho gấu trúc.
  • Đọc tệp dữ liệu giá trị phân tách dấu phẩy (CSV) với
           country  gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  \
    0    Australia     10039.59564     10949.64959     12217.22686
    1  New Zealand     10556.57566     12247.39532     13175.67800
    
       gdpPercap_1967  gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  \
    0     14526.12465     16788.62948     18334.19751     19477.00928
    1     14463.91893     16046.03728     16233.71770     17632.41040
    
       gdpPercap_1987  gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  \
    0     21888.88903     23424.76683     26997.93657     30687.75473
    1     19007.19129     18363.32494     21050.41377     23189.80135
    
       gdpPercap_2007
    0     34435.36744
    1     25185.00911
    
    9.
    • Đối số là tên của tệp sẽ được đọc.
    • Gán kết quả cho một biến để lưu trữ dữ liệu đã được đọc.

import pandas as pd

data = pd.read_csv('data/gapminder_gdp_oceania.csv')
print(data)

       country  gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  \
0    Australia     10039.59564     10949.64959     12217.22686
1  New Zealand     10556.57566     12247.39532     13175.67800

   gdpPercap_1967  gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  \
0     14526.12465     16788.62948     18334.19751     19477.00928
1     14463.91893     16046.03728     16233.71770     17632.41040

   gdpPercap_1987  gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  \
0     21888.88903     23424.76683     26997.93657     30687.75473
1     19007.19129     18363.32494     21050.41377     23189.80135

   gdpPercap_2007
0     34435.36744
1     25185.00911

  • Các cột trong khung dữ liệu là các biến quan sát và các hàng là các quan sát.
  • Pandas sử dụng Backslash
    FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv'
    
    0 để hiển thị các dòng được bọc khi đầu ra quá rộng để phù hợp với màn hình.

Tệp không tìm thấy

Bài học của chúng tôi lưu trữ các tệp dữ liệu của họ trong một thư mục phụ

FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv'
1, đó là lý do tại sao đường dẫn đến tệp là
FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv'
2. Nếu bạn quên bao gồm
FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv'
3 hoặc nếu bạn bao gồm nó nhưng bản sao của tệp của bạn ở một nơi khác, bạn sẽ gặp lỗi thời gian chạy kết thúc bằng một dòng như thế này:

FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv'

Sử dụng FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv' 4 để chỉ định rằng các giá trị cột nên được sử dụng làm tiêu đề hàng.

  • Các tiêu đề hàng là số (0 và 1 trong trường hợp này).
  • Thực sự muốn lập chỉ mục theo quốc gia.
  • Chuyển tên của cột đến
    FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv'
    
    5 dưới dạng tham số
    FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv'
    
    4 của nó để thực hiện việc này.

data = pd.read_csv('data/gapminder_gdp_oceania.csv', index_col='country')
print(data)

             gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
country
Australia       10039.59564     10949.64959     12217.22686     14526.12465
New Zealand     10556.57566     12247.39532     13175.67800     14463.91893

             gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
country
Australia       16788.62948     18334.19751     19477.00928     21888.88903
New Zealand     16046.03728     16233.71770     17632.41040     19007.19129

             gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
country
Australia       23424.76683     26997.93657     30687.75473     34435.36744
New Zealand     18363.32494     21050.41377     23189.80135     25185.00911

Sử dụng phương thức FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv' 7 để tìm hiểu thêm về DataFrame.


Index: 2 entries, Australia to New Zealand
Data columns (total 12 columns):
gdpPercap_1952    2 non-null float64
gdpPercap_1957    2 non-null float64
gdpPercap_1962    2 non-null float64
gdpPercap_1967    2 non-null float64
gdpPercap_1972    2 non-null float64
gdpPercap_1977    2 non-null float64
gdpPercap_1982    2 non-null float64
gdpPercap_1987    2 non-null float64
gdpPercap_1992    2 non-null float64
gdpPercap_1997    2 non-null float64
gdpPercap_2002    2 non-null float64
gdpPercap_2007    2 non-null float64
dtypes: float64(12)
memory usage: 208.0+ bytes

  • Đây là một
    FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv'
    
    8
  • Hai hàng có tên
    FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv'
    
    9 và
    data = pd.read_csv('data/gapminder_gdp_oceania.csv', index_col='country')
    print(data)
    
    0
  • Mười hai cột, mỗi cột có hai giá trị nổi 64 bit thực tế.
    • Chúng ta sẽ nói sau về các giá trị null, được sử dụng để thể hiện các quan sát bị thiếu.
  • Sử dụng 208 byte bộ nhớ.

Biến data = pd.read_csv('data/gapminder_gdp_oceania.csv', index_col='country') print(data) 1 lưu trữ thông tin về các cột DataFrame.

  • Lưu ý rằng đây là dữ liệu, không phải là một phương thức. (Nó không có dấu ngoặc đơn.)
    • Như
      data = pd.read_csv('data/gapminder_gdp_oceania.csv', index_col='country')
      print(data)
      
      2.
    • Vì vậy, không sử dụng
      data = pd.read_csv('data/gapminder_gdp_oceania.csv', index_col='country')
      print(data)
      
      3 để cố gắng gọi nó.
  • Được gọi là biến thành viên, hoặc chỉ là thành viên.

Index(['gdpPercap_1952', 'gdpPercap_1957', 'gdpPercap_1962', 'gdpPercap_1967',
       'gdpPercap_1972', 'gdpPercap_1977', 'gdpPercap_1982', 'gdpPercap_1987',
       'gdpPercap_1992', 'gdpPercap_1997', 'gdpPercap_2002', 'gdpPercap_2007'],
      dtype='object')

Sử dụng data = pd.read_csv('data/gapminder_gdp_oceania.csv', index_col='country') print(data) 4 để chuyển đổi DataFrame.

  • Đôi khi muốn coi các cột là hàng và ngược lại.
  • Chuyển đổi (viết
    data = pd.read_csv('data/gapminder_gdp_oceania.csv', index_col='country')
    print(data)
    
    5) không sao chép dữ liệu, chỉ cần thay đổi chế độ xem chương trình của nó.
  • Giống như
    data = pd.read_csv('data/gapminder_gdp_oceania.csv', index_col='country')
    print(data)
    
    6, nó là một biến thành viên.

country           Australia  New Zealand
gdpPercap_1952  10039.59564  10556.57566
gdpPercap_1957  10949.64959  12247.39532
gdpPercap_1962  12217.22686  13175.67800
gdpPercap_1967  14526.12465  14463.91893
gdpPercap_1972  16788.62948  16046.03728
gdpPercap_1977  18334.19751  16233.71770
gdpPercap_1982  19477.00928  17632.41040
gdpPercap_1987  21888.88903  19007.19129
gdpPercap_1992  23424.76683  18363.32494
gdpPercap_1997  26997.93657  21050.41377
gdpPercap_2002  30687.75473  23189.80135
gdpPercap_2007  34435.36744  25185.00911

Sử dụng data = pd.read_csv('data/gapminder_gdp_oceania.csv', index_col='country') print(data) 7 để có được số liệu thống kê tóm tắt về dữ liệu.

data = pd.read_csv('data/gapminder_gdp_oceania.csv', index_col='country')
print(data)
7 Nhận số liệu thống kê tóm tắt chỉ các cột có dữ liệu số. Tất cả các cột khác bị bỏ qua, trừ khi bạn sử dụng đối số
data = pd.read_csv('data/gapminder_gdp_oceania.csv', index_col='country')
print(data)
9.

       gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
count        2.000000        2.000000        2.000000        2.000000
mean     10298.085650    11598.522455    12696.452430    14495.021790
std        365.560078      917.644806      677.727301       43.986086
min      10039.595640    10949.649590    12217.226860    14463.918930
25%      10168.840645    11274.086022    12456.839645    14479.470360
50%      10298.085650    11598.522455    12696.452430    14495.021790
75%      10427.330655    11922.958888    12936.065215    14510.573220
max      10556.575660    12247.395320    13175.678000    14526.124650

       gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
count         2.00000        2.000000        2.000000        2.000000
mean      16417.33338    17283.957605    18554.709840    20448.040160
std         525.09198     1485.263517     1304.328377     2037.668013
min       16046.03728    16233.717700    17632.410400    19007.191290
25%       16231.68533    16758.837652    18093.560120    19727.615725
50%       16417.33338    17283.957605    18554.709840    20448.040160
75%       16602.98143    17809.077557    19015.859560    21168.464595
max       16788.62948    18334.197510    19477.009280    21888.889030

       gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
count        2.000000        2.000000        2.000000        2.000000
mean     20894.045885    24024.175170    26938.778040    29810.188275
std       3578.979883     4205.533703     5301.853680     6540.991104
min      18363.324940    21050.413770    23189.801350    25185.009110
25%      19628.685413    22537.294470    25064.289695    27497.598692
50%      20894.045885    24024.175170    26938.778040    29810.188275
75%      22159.406358    25511.055870    28813.266385    32122.777857
max      23424.766830    26997.936570    30687.754730    34435.367440

  • Không đặc biệt hữu ích chỉ với hai hồ sơ, nhưng rất hữu ích khi có hàng ngàn.

Đọc dữ liệu khác

Đọc dữ liệu trong

             gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
country
Australia       10039.59564     10949.64959     12217.22686     14526.12465
New Zealand     10556.57566     12247.39532     13175.67800     14463.91893

             gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
country
Australia       16788.62948     18334.19751     19477.00928     21888.88903
New Zealand     16046.03728     16233.71770     17632.41040     19007.19129

             gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
country
Australia       23424.76683     26997.93657     30687.75473     34435.36744
New Zealand     18363.32494     21050.41377     23189.80135     25185.00911
0 (nên nằm trong cùng thư mục với
             gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
country
Australia       10039.59564     10949.64959     12217.22686     14526.12465
New Zealand     10556.57566     12247.39532     13175.67800     14463.91893

             gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
country
Australia       16788.62948     18334.19751     19477.00928     21888.88903
New Zealand     16046.03728     16233.71770     17632.41040     19007.19129

             gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
country
Australia       23424.76683     26997.93657     30687.75473     34435.36744
New Zealand     18363.32494     21050.41377     23189.80135     25185.00911
1) thành một biến gọi là
             gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
country
Australia       10039.59564     10949.64959     12217.22686     14526.12465
New Zealand     10556.57566     12247.39532     13175.67800     14463.91893

             gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
country
Australia       16788.62948     18334.19751     19477.00928     21888.88903
New Zealand     16046.03728     16233.71770     17632.41040     19007.19129

             gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
country
Australia       23424.76683     26997.93657     30687.75473     34435.36744
New Zealand     18363.32494     21050.41377     23189.80135     25185.00911
2 và hiển thị số liệu thống kê tóm tắt của nó.

Dung dịch

Để đọc trong CSV, chúng tôi sử dụng

       country  gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  \
0    Australia     10039.59564     10949.64959     12217.22686
1  New Zealand     10556.57566     12247.39532     13175.67800

   gdpPercap_1967  gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  \
0     14526.12465     16788.62948     18334.19751     19477.00928
1     14463.91893     16046.03728     16233.71770     17632.41040

   gdpPercap_1987  gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  \
0     21888.88903     23424.76683     26997.93657     30687.75473
1     19007.19129     18363.32494     21050.41377     23189.80135

   gdpPercap_2007
0     34435.36744
1     25185.00911
9 và chuyển tên tệp
             gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
country
Australia       10039.59564     10949.64959     12217.22686     14526.12465
New Zealand     10556.57566     12247.39532     13175.67800     14463.91893

             gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
country
Australia       16788.62948     18334.19751     19477.00928     21888.88903
New Zealand     16046.03728     16233.71770     17632.41040     19007.19129

             gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
country
Australia       23424.76683     26997.93657     30687.75473     34435.36744
New Zealand     18363.32494     21050.41377     23189.80135     25185.00911
4 cho nó. Chúng tôi cũng một lần nữa chuyển tên cột
             gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
country
Australia       10039.59564     10949.64959     12217.22686     14526.12465
New Zealand     10556.57566     12247.39532     13175.67800     14463.91893

             gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
country
Australia       16788.62948     18334.19751     19477.00928     21888.88903
New Zealand     16046.03728     16233.71770     17632.41040     19007.19129

             gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
country
Australia       23424.76683     26997.93657     30687.75473     34435.36744
New Zealand     18363.32494     21050.41377     23189.80135     25185.00911
5 cho tham số
FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv'
4 để lập chỉ mục theo quốc gia. Các số liệu thống kê tóm tắt có thể được hiển thị với phương pháp
data = pd.read_csv('data/gapminder_gdp_oceania.csv', index_col='country')
print(data)
7.

americas = pd.read_csv('data/gapminder_gdp_americas.csv', index_col='country')
americas.describe()

Kiểm tra dữ liệu

Sau khi đọc dữ liệu cho Châu Mỹ, hãy sử dụng

             gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
country
Australia       10039.59564     10949.64959     12217.22686     14526.12465
New Zealand     10556.57566     12247.39532     13175.67800     14463.91893

             gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
country
Australia       16788.62948     18334.19751     19477.00928     21888.88903
New Zealand     16046.03728     16233.71770     17632.41040     19007.19129

             gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
country
Australia       23424.76683     26997.93657     30687.75473     34435.36744
New Zealand     18363.32494     21050.41377     23189.80135     25185.00911
8 và
             gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
country
Australia       10039.59564     10949.64959     12217.22686     14526.12465
New Zealand     10556.57566     12247.39532     13175.67800     14463.91893

             gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
country
Australia       16788.62948     18334.19751     19477.00928     21888.88903
New Zealand     16046.03728     16233.71770     17632.41040     19007.19129

             gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
country
Australia       23424.76683     26997.93657     30687.75473     34435.36744
New Zealand     18363.32494     21050.41377     23189.80135     25185.00911
9 để tìm hiểu những gì

Index: 2 entries, Australia to New Zealand
Data columns (total 12 columns):
gdpPercap_1952    2 non-null float64
gdpPercap_1957    2 non-null float64
gdpPercap_1962    2 non-null float64
gdpPercap_1967    2 non-null float64
gdpPercap_1972    2 non-null float64
gdpPercap_1977    2 non-null float64
gdpPercap_1982    2 non-null float64
gdpPercap_1987    2 non-null float64
gdpPercap_1992    2 non-null float64
gdpPercap_1997    2 non-null float64
gdpPercap_2002    2 non-null float64
gdpPercap_2007    2 non-null float64
dtypes: float64(12)
memory usage: 208.0+ bytes
0 và

Index: 2 entries, Australia to New Zealand
Data columns (total 12 columns):
gdpPercap_1952    2 non-null float64
gdpPercap_1957    2 non-null float64
gdpPercap_1962    2 non-null float64
gdpPercap_1967    2 non-null float64
gdpPercap_1972    2 non-null float64
gdpPercap_1977    2 non-null float64
gdpPercap_1982    2 non-null float64
gdpPercap_1987    2 non-null float64
gdpPercap_1992    2 non-null float64
gdpPercap_1997    2 non-null float64
gdpPercap_2002    2 non-null float64
gdpPercap_2007    2 non-null float64
dtypes: float64(12)
memory usage: 208.0+ bytes
1 làm.

  1. Cuộc gọi phương thức nào sẽ hiển thị ba hàng đầu tiên của dữ liệu này?
  2. Cuộc gọi phương thức nào sẽ hiển thị ba cột cuối cùng của dữ liệu này? (Gợi ý: Bạn có thể cần thay đổi quan điểm của mình về dữ liệu.)

Dung dịch

  1. Để đọc trong CSV, chúng tôi sử dụng

           country  gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  \
    0    Australia     10039.59564     10949.64959     12217.22686
    1  New Zealand     10556.57566     12247.39532     13175.67800
    
       gdpPercap_1967  gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  \
    0     14526.12465     16788.62948     18334.19751     19477.00928
    1     14463.91893     16046.03728     16233.71770     17632.41040
    
       gdpPercap_1987  gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  \
    0     21888.88903     23424.76683     26997.93657     30687.75473
    1     19007.19129     18363.32494     21050.41377     23189.80135
    
       gdpPercap_2007
    0     34435.36744
    1     25185.00911
    
    9 và chuyển tên tệp
                 gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
    country
    Australia       10039.59564     10949.64959     12217.22686     14526.12465
    New Zealand     10556.57566     12247.39532     13175.67800     14463.91893
    
                 gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
    country
    Australia       16788.62948     18334.19751     19477.00928     21888.88903
    New Zealand     16046.03728     16233.71770     17632.41040     19007.19129
    
                 gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
    country
    Australia       23424.76683     26997.93657     30687.75473     34435.36744
    New Zealand     18363.32494     21050.41377     23189.80135     25185.00911
    
    4 cho nó. Chúng tôi cũng một lần nữa chuyển tên cột
                 gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
    country
    Australia       10039.59564     10949.64959     12217.22686     14526.12465
    New Zealand     10556.57566     12247.39532     13175.67800     14463.91893
    
                 gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
    country
    Australia       16788.62948     18334.19751     19477.00928     21888.88903
    New Zealand     16046.03728     16233.71770     17632.41040     19007.19129
    
                 gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
    country
    Australia       23424.76683     26997.93657     30687.75473     34435.36744
    New Zealand     18363.32494     21050.41377     23189.80135     25185.00911
    
    5 cho tham số
    FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv'
    
    4 để lập chỉ mục theo quốc gia. Các số liệu thống kê tóm tắt có thể được hiển thị với phương pháp
    data = pd.read_csv('data/gapminder_gdp_oceania.csv', index_col='country')
    print(data)
    
    7.

           country  gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  \
    0    Australia     10039.59564     10949.64959     12217.22686
    1  New Zealand     10556.57566     12247.39532     13175.67800
    
       gdpPercap_1967  gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  \
    0     14526.12465     16788.62948     18334.19751     19477.00928
    1     14463.91893     16046.03728     16233.71770     17632.41040
    
       gdpPercap_1987  gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  \
    0     21888.88903     23424.76683     26997.93657     30687.75473
    1     19007.19129     18363.32494     21050.41377     23189.80135
    
       gdpPercap_2007
    0     34435.36744
    1     25185.00911
    
    0

  2. Kiểm tra dữ liệu

           country  gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  \
    0    Australia     10039.59564     10949.64959     12217.22686
    1  New Zealand     10556.57566     12247.39532     13175.67800
    
       gdpPercap_1967  gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  \
    0     14526.12465     16788.62948     18334.19751     19477.00928
    1     14463.91893     16046.03728     16233.71770     17632.41040
    
       gdpPercap_1987  gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  \
    0     21888.88903     23424.76683     26997.93657     30687.75473
    1     19007.19129     18363.32494     21050.41377     23189.80135
    
       gdpPercap_2007
    0     34435.36744
    1     25185.00911
    
    1

    Sau khi đọc dữ liệu cho Châu Mỹ, hãy sử dụng

                 gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
    country
    Australia       10039.59564     10949.64959     12217.22686     14526.12465
    New Zealand     10556.57566     12247.39532     13175.67800     14463.91893
    
                 gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
    country
    Australia       16788.62948     18334.19751     19477.00928     21888.88903
    New Zealand     16046.03728     16233.71770     17632.41040     19007.19129
    
                 gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
    country
    Australia       23424.76683     26997.93657     30687.75473     34435.36744
    New Zealand     18363.32494     21050.41377     23189.80135     25185.00911
    
    8 và
                 gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
    country
    Australia       10039.59564     10949.64959     12217.22686     14526.12465
    New Zealand     10556.57566     12247.39532     13175.67800     14463.91893
    
                 gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
    country
    Australia       16788.62948     18334.19751     19477.00928     21888.88903
    New Zealand     16046.03728     16233.71770     17632.41040     19007.19129
    
                 gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
    country
    Australia       23424.76683     26997.93657     30687.75473     34435.36744
    New Zealand     18363.32494     21050.41377     23189.80135     25185.00911
    
    9 để tìm hiểu những gì
    
    Index: 2 entries, Australia to New Zealand
    Data columns (total 12 columns):
    gdpPercap_1952    2 non-null float64
    gdpPercap_1957    2 non-null float64
    gdpPercap_1962    2 non-null float64
    gdpPercap_1967    2 non-null float64
    gdpPercap_1972    2 non-null float64
    gdpPercap_1977    2 non-null float64
    gdpPercap_1982    2 non-null float64
    gdpPercap_1987    2 non-null float64
    gdpPercap_1992    2 non-null float64
    gdpPercap_1997    2 non-null float64
    gdpPercap_2002    2 non-null float64
    gdpPercap_2007    2 non-null float64
    dtypes: float64(12)
    memory usage: 208.0+ bytes
    
    0 và
    
    Index: 2 entries, Australia to New Zealand
    Data columns (total 12 columns):
    gdpPercap_1952    2 non-null float64
    gdpPercap_1957    2 non-null float64
    gdpPercap_1962    2 non-null float64
    gdpPercap_1967    2 non-null float64
    gdpPercap_1972    2 non-null float64
    gdpPercap_1977    2 non-null float64
    gdpPercap_1982    2 non-null float64
    gdpPercap_1987    2 non-null float64
    gdpPercap_1992    2 non-null float64
    gdpPercap_1997    2 non-null float64
    gdpPercap_2002    2 non-null float64
    gdpPercap_2007    2 non-null float64
    dtypes: float64(12)
    memory usage: 208.0+ bytes
    
    1 làm.

           country  gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  \
    0    Australia     10039.59564     10949.64959     12217.22686
    1  New Zealand     10556.57566     12247.39532     13175.67800
    
       gdpPercap_1967  gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  \
    0     14526.12465     16788.62948     18334.19751     19477.00928
    1     14463.91893     16046.03728     16233.71770     17632.41040
    
       gdpPercap_1987  gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  \
    0     21888.88903     23424.76683     26997.93657     30687.75473
    1     19007.19129     18363.32494     21050.41377     23189.80135
    
       gdpPercap_2007
    0     34435.36744
    1     25185.00911
    
    2

           country  gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  \
    0    Australia     10039.59564     10949.64959     12217.22686
    1  New Zealand     10556.57566     12247.39532     13175.67800
    
       gdpPercap_1967  gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  \
    0     14526.12465     16788.62948     18334.19751     19477.00928
    1     14463.91893     16046.03728     16233.71770     17632.41040
    
       gdpPercap_1987  gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  \
    0     21888.88903     23424.76683     26997.93657     30687.75473
    1     19007.19129     18363.32494     21050.41377     23189.80135
    
       gdpPercap_2007
    0     34435.36744
    1     25185.00911
    
    3

    Cuộc gọi phương thức nào sẽ hiển thị ba hàng đầu tiên của dữ liệu này?

           country  gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  \
    0    Australia     10039.59564     10949.64959     12217.22686
    1  New Zealand     10556.57566     12247.39532     13175.67800
    
       gdpPercap_1967  gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  \
    0     14526.12465     16788.62948     18334.19751     19477.00928
    1     14463.91893     16046.03728     16233.71770     17632.41040
    
       gdpPercap_1987  gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  \
    0     21888.88903     23424.76683     26997.93657     30687.75473
    1     19007.19129     18363.32494     21050.41377     23189.80135
    
       gdpPercap_2007
    0     34435.36744
    1     25185.00911
    
    4

    Cuộc gọi phương thức nào sẽ hiển thị ba cột cuối cùng của dữ liệu này? (Gợi ý: Bạn có thể cần thay đổi quan điểm của mình về dữ liệu.) we could have done the above in a single line of code by ‘chaining’ the commands:

Chúng tôi có thể kiểm tra năm hàng đầu tiên của gdpPercap_1952 gdpPercap_1957 gdpPercap_1962 gdpPercap_1967 \ country Australia 10039.59564 10949.64959 12217.22686 14526.12465 New Zealand 10556.57566 12247.39532 13175.67800 14463.91893 gdpPercap_1972 gdpPercap_1977 gdpPercap_1982 gdpPercap_1987 \ country Australia 16788.62948 18334.19751 19477.00928 21888.88903 New Zealand 16046.03728 16233.71770 17632.41040 19007.19129 gdpPercap_1992 gdpPercap_1997 gdpPercap_2002 gdpPercap_2007 country Australia 23424.76683 26997.93657 30687.75473 34435.36744 New Zealand 18363.32494 21050.41377 23189.80135 25185.00911 2 bằng cách thực thi Index: 2 entries, Australia to New Zealand Data columns (total 12 columns): gdpPercap_1952 2 non-null float64 gdpPercap_1957 2 non-null float64 gdpPercap_1962 2 non-null float64 gdpPercap_1967 2 non-null float64 gdpPercap_1972 2 non-null float64 gdpPercap_1977 2 non-null float64 gdpPercap_1982 2 non-null float64 gdpPercap_1987 2 non-null float64 gdpPercap_1992 2 non-null float64 gdpPercap_1997 2 non-null float64 gdpPercap_2002 2 non-null float64 gdpPercap_2007 2 non-null float64 dtypes: float64(12) memory usage: 208.0+ bytes 3 (cho phép chúng tôi xem đầu của DataFrame). Chúng tôi có thể chỉ định số lượng hàng mà chúng tôi muốn xem bằng cách chỉ định tham số Index: 2 entries, Australia to New Zealand Data columns (total 12 columns): gdpPercap_1952 2 non-null float64 gdpPercap_1957 2 non-null float64 gdpPercap_1962 2 non-null float64 gdpPercap_1967 2 non-null float64 gdpPercap_1972 2 non-null float64 gdpPercap_1977 2 non-null float64 gdpPercap_1982 2 non-null float64 gdpPercap_1987 2 non-null float64 gdpPercap_1992 2 non-null float64 gdpPercap_1997 2 non-null float64 gdpPercap_2002 2 non-null float64 gdpPercap_2007 2 non-null float64 dtypes: float64(12) memory usage: 208.0+ bytes 4 trong cuộc gọi của chúng tôi đến Index: 2 entries, Australia to New Zealand Data columns (total 12 columns): gdpPercap_1952 2 non-null float64 gdpPercap_1957 2 non-null float64 gdpPercap_1962 2 non-null float64 gdpPercap_1967 2 non-null float64 gdpPercap_1972 2 non-null float64 gdpPercap_1977 2 non-null float64 gdpPercap_1982 2 non-null float64 gdpPercap_1987 2 non-null float64 gdpPercap_1992 2 non-null float64 gdpPercap_1997 2 non-null float64 gdpPercap_2002 2 non-null float64 gdpPercap_2007 2 non-null float64 dtypes: float64(12) memory usage: 208.0+ bytes 3. Để xem ba hàng đầu tiên, thực thi:

Để kiểm tra ba hàng cuối cùng của

             gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
country
Australia       10039.59564     10949.64959     12217.22686     14526.12465
New Zealand     10556.57566     12247.39532     13175.67800     14463.91893

             gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
country
Australia       16788.62948     18334.19751     19477.00928     21888.88903
New Zealand     16046.03728     16233.71770     17632.41040     19007.19129

             gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
country
Australia       23424.76683     26997.93657     30687.75473     34435.36744
New Zealand     18363.32494     21050.41377     23189.80135     25185.00911
2, chúng tôi sẽ sử dụng lệnh,

Index: 2 entries, Australia to New Zealand
Data columns (total 12 columns):
gdpPercap_1952    2 non-null float64
gdpPercap_1957    2 non-null float64
gdpPercap_1962    2 non-null float64
gdpPercap_1967    2 non-null float64
gdpPercap_1972    2 non-null float64
gdpPercap_1977    2 non-null float64
gdpPercap_1982    2 non-null float64
gdpPercap_1987    2 non-null float64
gdpPercap_1992    2 non-null float64
gdpPercap_1997    2 non-null float64
gdpPercap_2002    2 non-null float64
gdpPercap_2007    2 non-null float64
dtypes: float64(12)
memory usage: 208.0+ bytes
7, tương tự như

Index: 2 entries, Australia to New Zealand
Data columns (total 12 columns):
gdpPercap_1952    2 non-null float64
gdpPercap_1957    2 non-null float64
gdpPercap_1962    2 non-null float64
gdpPercap_1967    2 non-null float64
gdpPercap_1972    2 non-null float64
gdpPercap_1977    2 non-null float64
gdpPercap_1982    2 non-null float64
gdpPercap_1987    2 non-null float64
gdpPercap_1992    2 non-null float64
gdpPercap_1997    2 non-null float64
gdpPercap_2002    2 non-null float64
gdpPercap_2007    2 non-null float64
dtypes: float64(12)
memory usage: 208.0+ bytes
8 được sử dụng ở trên. Tuy nhiên, ở đây chúng tôi muốn xem xét ba cột cuối cùng vì vậy chúng tôi cần thay đổi quan điểm của mình và sau đó sử dụng

Index: 2 entries, Australia to New Zealand
Data columns (total 12 columns):
gdpPercap_1952    2 non-null float64
gdpPercap_1957    2 non-null float64
gdpPercap_1962    2 non-null float64
gdpPercap_1967    2 non-null float64
gdpPercap_1972    2 non-null float64
gdpPercap_1977    2 non-null float64
gdpPercap_1982    2 non-null float64
gdpPercap_1987    2 non-null float64
gdpPercap_1992    2 non-null float64
gdpPercap_1997    2 non-null float64
gdpPercap_2002    2 non-null float64
gdpPercap_2007    2 non-null float64
dtypes: float64(12)
memory usage: 208.0+ bytes
9. Để làm như vậy, chúng tôi tạo một khung dữ liệu mới trong đó các hàng và cột được chuyển đổi:

       country  gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  \
0    Australia     10039.59564     10949.64959     12217.22686
1  New Zealand     10556.57566     12247.39532     13175.67800

   gdpPercap_1967  gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  \
0     14526.12465     16788.62948     18334.19751     19477.00928
1     14463.91893     16046.03728     16233.71770     17632.41040

   gdpPercap_1987  gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  \
0     21888.88903     23424.76683     26997.93657     30687.75473
1     19007.19129     18363.32494     21050.41377     23189.80135

   gdpPercap_2007
0     34435.36744
1     25185.00911
5

Giá trị nào bạn nên chuyển sang

FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv'
5 để đọc
Index(['gdpPercap_1952', 'gdpPercap_1957', 'gdpPercap_1962', 'gdpPercap_1967',
       'gdpPercap_1972', 'gdpPercap_1977', 'gdpPercap_1982', 'gdpPercap_1987',
       'gdpPercap_1992', 'gdpPercap_1997', 'gdpPercap_2002', 'gdpPercap_2007'],
      dtype='object')
2 trong
Index(['gdpPercap_1952', 'gdpPercap_1957', 'gdpPercap_1962', 'gdpPercap_1967',
       'gdpPercap_1972', 'gdpPercap_1977', 'gdpPercap_1982', 'gdpPercap_1987',
       'gdpPercap_1992', 'gdpPercap_1997', 'gdpPercap_2002', 'gdpPercap_2007'],
      dtype='object')
4?

Dung dịch

Chúng ta cần chỉ định đường dẫn đến tệp quan tâm trong cuộc gọi đến

       country  gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  \
0    Australia     10039.59564     10949.64959     12217.22686
1  New Zealand     10556.57566     12247.39532     13175.67800

   gdpPercap_1967  gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  \
0     14526.12465     16788.62948     18334.19751     19477.00928
1     14463.91893     16046.03728     16233.71770     17632.41040

   gdpPercap_1987  gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  \
0     21888.88903     23424.76683     26997.93657     30687.75473
1     19007.19129     18363.32494     21050.41377     23189.80135

   gdpPercap_2007
0     34435.36744
1     25185.00911
9. Trước tiên chúng ta cần phải nhảy ra khỏi thư mục
Index(['gdpPercap_1952', 'gdpPercap_1957', 'gdpPercap_1962', 'gdpPercap_1967',
       'gdpPercap_1972', 'gdpPercap_1977', 'gdpPercap_1982', 'gdpPercap_1987',
       'gdpPercap_1992', 'gdpPercap_1997', 'gdpPercap_2002', 'gdpPercap_2007'],
      dtype='object')
5 bằng cách sử dụng ‘../, sau đó vào thư mục
Index(['gdpPercap_1952', 'gdpPercap_1957', 'gdpPercap_1962', 'gdpPercap_1967',
       'gdpPercap_1972', 'gdpPercap_1977', 'gdpPercap_1982', 'gdpPercap_1987',
       'gdpPercap_1992', 'gdpPercap_1997', 'gdpPercap_2002', 'gdpPercap_2007'],
      dtype='object')
3 bằng cách sử dụng‘ field_data/hồi. Sau đó, chúng ta có thể chỉ định tên tệp `vi khuẩn.csv. Kết quả là như sau:

       country  gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  \
0    Australia     10039.59564     10949.64959     12217.22686
1  New Zealand     10556.57566     12247.39532     13175.67800

   gdpPercap_1967  gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  \
0     14526.12465     16788.62948     18334.19751     19477.00928
1     14463.91893     16046.03728     16233.71770     17632.41040

   gdpPercap_1987  gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  \
0     21888.88903     23424.76683     26997.93657     30687.75473
1     19007.19129     18363.32494     21050.41377     23189.80135

   gdpPercap_2007
0     34435.36744
1     25185.00911
6

Viết dữ liệu

Cũng như chức năng

FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv'
5 để đọc dữ liệu từ một tệp, Pandas cung cấp chức năng
country           Australia  New Zealand
gdpPercap_1952  10039.59564  10556.57566
gdpPercap_1957  10949.64959  12247.39532
gdpPercap_1962  12217.22686  13175.67800
gdpPercap_1967  14526.12465  14463.91893
gdpPercap_1972  16788.62948  16046.03728
gdpPercap_1977  18334.19751  16233.71770
gdpPercap_1982  19477.00928  17632.41040
gdpPercap_1987  21888.88903  19007.19129
gdpPercap_1992  23424.76683  18363.32494
gdpPercap_1997  26997.93657  21050.41377
gdpPercap_2002  30687.75473  23189.80135
gdpPercap_2007  34435.36744  25185.00911
3 để ghi dữ liệu vào các tệp. Áp dụng những gì bạn đã học về việc đọc từ các tệp, hãy viết một trong các khung dữ liệu của bạn vào một tệp có tên
country           Australia  New Zealand
gdpPercap_1952  10039.59564  10556.57566
gdpPercap_1957  10949.64959  12247.39532
gdpPercap_1962  12217.22686  13175.67800
gdpPercap_1967  14526.12465  14463.91893
gdpPercap_1972  16788.62948  16046.03728
gdpPercap_1977  18334.19751  16233.71770
gdpPercap_1982  19477.00928  17632.41040
gdpPercap_1987  21888.88903  19007.19129
gdpPercap_1992  23424.76683  18363.32494
gdpPercap_1997  26997.93657  21050.41377
gdpPercap_2002  30687.75473  23189.80135
gdpPercap_2007  34435.36744  25185.00911
4. Bạn có thể sử dụng
country           Australia  New Zealand
gdpPercap_1952  10039.59564  10556.57566
gdpPercap_1957  10949.64959  12247.39532
gdpPercap_1962  12217.22686  13175.67800
gdpPercap_1967  14526.12465  14463.91893
gdpPercap_1972  16788.62948  16046.03728
gdpPercap_1977  18334.19751  16233.71770
gdpPercap_1982  19477.00928  17632.41040
gdpPercap_1987  21888.88903  19007.19129
gdpPercap_1992  23424.76683  18363.32494
gdpPercap_1997  26997.93657  21050.41377
gdpPercap_2002  30687.75473  23189.80135
gdpPercap_2007  34435.36744  25185.00911
5 để có được thông tin về cách sử dụng
country           Australia  New Zealand
gdpPercap_1952  10039.59564  10556.57566
gdpPercap_1957  10949.64959  12247.39532
gdpPercap_1962  12217.22686  13175.67800
gdpPercap_1967  14526.12465  14463.91893
gdpPercap_1972  16788.62948  16046.03728
gdpPercap_1977  18334.19751  16233.71770
gdpPercap_1982  19477.00928  17632.41040
gdpPercap_1987  21888.88903  19007.19129
gdpPercap_1992  23424.76683  18363.32494
gdpPercap_1997  26997.93657  21050.41377
gdpPercap_2002  30687.75473  23189.80135
gdpPercap_2007  34435.36744  25185.00911
3.

Dung dịch

Chúng ta cần chỉ định đường dẫn đến tệp quan tâm trong cuộc gọi đến

       country  gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  \
0    Australia     10039.59564     10949.64959     12217.22686
1  New Zealand     10556.57566     12247.39532     13175.67800

   gdpPercap_1967  gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  \
0     14526.12465     16788.62948     18334.19751     19477.00928
1     14463.91893     16046.03728     16233.71770     17632.41040

   gdpPercap_1987  gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  \
0     21888.88903     23424.76683     26997.93657     30687.75473
1     19007.19129     18363.32494     21050.41377     23189.80135

   gdpPercap_2007
0     34435.36744
1     25185.00911
9. Trước tiên chúng ta cần phải nhảy ra khỏi thư mục
Index(['gdpPercap_1952', 'gdpPercap_1957', 'gdpPercap_1962', 'gdpPercap_1967',
       'gdpPercap_1972', 'gdpPercap_1977', 'gdpPercap_1982', 'gdpPercap_1987',
       'gdpPercap_1992', 'gdpPercap_1997', 'gdpPercap_2002', 'gdpPercap_2007'],
      dtype='object')
5 bằng cách sử dụng ‘../, sau đó vào thư mục
Index(['gdpPercap_1952', 'gdpPercap_1957', 'gdpPercap_1962', 'gdpPercap_1967',
       'gdpPercap_1972', 'gdpPercap_1977', 'gdpPercap_1982', 'gdpPercap_1987',
       'gdpPercap_1992', 'gdpPercap_1997', 'gdpPercap_2002', 'gdpPercap_2007'],
      dtype='object')
3 bằng cách sử dụng‘ field_data/hồi. Sau đó, chúng ta có thể chỉ định tên tệp `vi khuẩn.csv. Kết quả là như sau:

       country  gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  \
0    Australia     10039.59564     10949.64959     12217.22686
1  New Zealand     10556.57566     12247.39532     13175.67800

   gdpPercap_1967  gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  \
0     14526.12465     16788.62948     18334.19751     19477.00928
1     14463.91893     16046.03728     16233.71770     17632.41040

   gdpPercap_1987  gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  \
0     21888.88903     23424.76683     26997.93657     30687.75473
1     19007.19129     18363.32494     21050.41377     23189.80135

   gdpPercap_2007
0     34435.36744
1     25185.00911
7

Viết dữ liệu

Cũng như chức năng

FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv'
5 để đọc dữ liệu từ một tệp, Pandas cung cấp chức năng
country           Australia  New Zealand
gdpPercap_1952  10039.59564  10556.57566
gdpPercap_1957  10949.64959  12247.39532
gdpPercap_1962  12217.22686  13175.67800
gdpPercap_1967  14526.12465  14463.91893
gdpPercap_1972  16788.62948  16046.03728
gdpPercap_1977  18334.19751  16233.71770
gdpPercap_1982  19477.00928  17632.41040
gdpPercap_1987  21888.88903  19007.19129
gdpPercap_1992  23424.76683  18363.32494
gdpPercap_1997  26997.93657  21050.41377
gdpPercap_2002  30687.75473  23189.80135
gdpPercap_2007  34435.36744  25185.00911
3 để ghi dữ liệu vào các tệp. Áp dụng những gì bạn đã học về việc đọc từ các tệp, hãy viết một trong các khung dữ liệu của bạn vào một tệp có tên
country           Australia  New Zealand
gdpPercap_1952  10039.59564  10556.57566
gdpPercap_1957  10949.64959  12247.39532
gdpPercap_1962  12217.22686  13175.67800
gdpPercap_1967  14526.12465  14463.91893
gdpPercap_1972  16788.62948  16046.03728
gdpPercap_1977  18334.19751  16233.71770
gdpPercap_1982  19477.00928  17632.41040
gdpPercap_1987  21888.88903  19007.19129
gdpPercap_1992  23424.76683  18363.32494
gdpPercap_1997  26997.93657  21050.41377
gdpPercap_2002  30687.75473  23189.80135
gdpPercap_2007  34435.36744  25185.00911
4. Bạn có thể sử dụng
country           Australia  New Zealand
gdpPercap_1952  10039.59564  10556.57566
gdpPercap_1957  10949.64959  12247.39532
gdpPercap_1962  12217.22686  13175.67800
gdpPercap_1967  14526.12465  14463.91893
gdpPercap_1972  16788.62948  16046.03728
gdpPercap_1977  18334.19751  16233.71770
gdpPercap_1982  19477.00928  17632.41040
gdpPercap_1987  21888.88903  19007.19129
gdpPercap_1992  23424.76683  18363.32494
gdpPercap_1997  26997.93657  21050.41377
gdpPercap_2002  30687.75473  23189.80135
gdpPercap_2007  34435.36744  25185.00911
5 để có được thông tin về cách sử dụng
country           Australia  New Zealand
gdpPercap_1952  10039.59564  10556.57566
gdpPercap_1957  10949.64959  12247.39532
gdpPercap_1962  12217.22686  13175.67800
gdpPercap_1967  14526.12465  14463.91893
gdpPercap_1972  16788.62948  16046.03728
gdpPercap_1977  18334.19751  16233.71770
gdpPercap_1982  19477.00928  17632.41040
gdpPercap_1987  21888.88903  19007.19129
gdpPercap_1992  23424.76683  18363.32494
gdpPercap_1997  26997.93657  21050.41377
gdpPercap_2002  30687.75473  23189.80135
gdpPercap_2007  34435.36744  25185.00911
3.

Để ghi DataFrame gdpPercap_1952 gdpPercap_1957 gdpPercap_1962 gdpPercap_1967 \ country Australia 10039.59564 10949.64959 12217.22686 14526.12465 New Zealand 10556.57566 12247.39532 13175.67800 14463.91893 gdpPercap_1972 gdpPercap_1977 gdpPercap_1982 gdpPercap_1987 \ country Australia 16788.62948 18334.19751 19477.00928 21888.88903 New Zealand 16046.03728 16233.71770 17632.41040 19007.19129 gdpPercap_1992 gdpPercap_1997 gdpPercap_2002 gdpPercap_2007 country Australia 23424.76683 26997.93657 30687.75473 34435.36744 New Zealand 18363.32494 21050.41377 23189.80135 25185.00911 2 vào một tệp có tên country Australia New Zealand gdpPercap_1952 10039.59564 10556.57566 gdpPercap_1957 10949.64959 12247.39532 gdpPercap_1962 12217.22686 13175.67800 gdpPercap_1967 14526.12465 14463.91893 gdpPercap_1972 16788.62948 16046.03728 gdpPercap_1977 18334.19751 16233.71770 gdpPercap_1982 19477.00928 17632.41040 gdpPercap_1987 21888.88903 19007.19129 gdpPercap_1992 23424.76683 18363.32494 gdpPercap_1997 26997.93657 21050.41377 gdpPercap_2002 30687.75473 23189.80135 gdpPercap_2007 34435.36744 25185.00911 4, hãy thực hiện lệnh sau:

  • Để được trợ giúp trên

    country           Australia  New Zealand
    gdpPercap_1952  10039.59564  10556.57566
    gdpPercap_1957  10949.64959  12247.39532
    gdpPercap_1962  12217.22686  13175.67800
    gdpPercap_1967  14526.12465  14463.91893
    gdpPercap_1972  16788.62948  16046.03728
    gdpPercap_1977  18334.19751  16233.71770
    gdpPercap_1982  19477.00928  17632.41040
    gdpPercap_1987  21888.88903  19007.19129
    gdpPercap_1992  23424.76683  18363.32494
    gdpPercap_1997  26997.93657  21050.41377
    gdpPercap_2002  30687.75473  23189.80135
    gdpPercap_2007  34435.36744  25185.00911
    
    3, bạn có thể thực hiện, ví dụ:

  • Lưu ý rằng

           gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
    count        2.000000        2.000000        2.000000        2.000000
    mean     10298.085650    11598.522455    12696.452430    14495.021790
    std        365.560078      917.644806      677.727301       43.986086
    min      10039.595640    10949.649590    12217.226860    14463.918930
    25%      10168.840645    11274.086022    12456.839645    14479.470360
    50%      10298.085650    11598.522455    12696.452430    14495.021790
    75%      10427.330655    11922.958888    12936.065215    14510.573220
    max      10556.575660    12247.395320    13175.678000    14526.124650
    
           gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
    count         2.00000        2.000000        2.000000        2.000000
    mean      16417.33338    17283.957605    18554.709840    20448.040160
    std         525.09198     1485.263517     1304.328377     2037.668013
    min       16046.03728    16233.717700    17632.410400    19007.191290
    25%       16231.68533    16758.837652    18093.560120    19727.615725
    50%       16417.33338    17283.957605    18554.709840    20448.040160
    75%       16602.98143    17809.077557    19015.859560    21168.464595
    max       16788.62948    18334.197510    19477.009280    21888.889030
    
           gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
    count        2.000000        2.000000        2.000000        2.000000
    mean     20894.045885    24024.175170    26938.778040    29810.188275
    std       3578.979883     4205.533703     5301.853680     6540.991104
    min      18363.324940    21050.413770    23189.801350    25185.009110
    25%      19628.685413    22537.294470    25064.289695    27497.598692
    50%      20894.045885    24024.175170    26938.778040    29810.188275
    75%      22159.406358    25511.055870    28813.266385    32122.777857
    max      23424.766830    26997.936570    30687.754730    34435.367440
    
    0 ném lỗi! Đây là một sự tinh tế và là do thực tế là
    country           Australia  New Zealand
    gdpPercap_1952  10039.59564  10556.57566
    gdpPercap_1957  10949.64959  12247.39532
    gdpPercap_1962  12217.22686  13175.67800
    gdpPercap_1967  14526.12465  14463.91893
    gdpPercap_1972  16788.62948  16046.03728
    gdpPercap_1977  18334.19751  16233.71770
    gdpPercap_1982  19477.00928  17632.41040
    gdpPercap_1987  21888.88903  19007.19129
    gdpPercap_1992  23424.76683  18363.32494
    gdpPercap_1997  26997.93657  21050.41377
    gdpPercap_2002  30687.75473  23189.80135
    gdpPercap_2007  34435.36744  25185.00911
    
    3 không phải là một chức năng trong chính nó và cuộc gọi thực tế là
           gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
    count        2.000000        2.000000        2.000000        2.000000
    mean     10298.085650    11598.522455    12696.452430    14495.021790
    std        365.560078      917.644806      677.727301       43.986086
    min      10039.595640    10949.649590    12217.226860    14463.918930
    25%      10168.840645    11274.086022    12456.839645    14479.470360
    50%      10298.085650    11598.522455    12696.452430    14495.021790
    75%      10427.330655    11922.958888    12936.065215    14510.573220
    max      10556.575660    12247.395320    13175.678000    14526.124650
    
           gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
    count         2.00000        2.000000        2.000000        2.000000
    mean      16417.33338    17283.957605    18554.709840    20448.040160
    std         525.09198     1485.263517     1304.328377     2037.668013
    min       16046.03728    16233.717700    17632.410400    19007.191290
    25%       16231.68533    16758.837652    18093.560120    19727.615725
    50%       16417.33338    17283.957605    18554.709840    20448.040160
    75%       16602.98143    17809.077557    19015.859560    21168.464595
    max       16788.62948    18334.197510    19477.009280    21888.889030
    
           gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
    count        2.000000        2.000000        2.000000        2.000000
    mean     20894.045885    24024.175170    26938.778040    29810.188275
    std       3578.979883     4205.533703     5301.853680     6540.991104
    min      18363.324940    21050.413770    23189.801350    25185.009110
    25%      19628.685413    22537.294470    25064.289695    27497.598692
    50%      20894.045885    24024.175170    26938.778040    29810.188275
    75%      22159.406358    25511.055870    28813.266385    32122.777857
    max      23424.766830    26997.936570    30687.754730    34435.367440
    
    2.

  • Những điểm chính

  • Sử dụng thư viện PANDAS để lấy số liệu thống kê cơ bản ra khỏi dữ liệu bảng.

  • Sử dụng

    FileNotFoundError: [Errno 2] No such file or directory: 'data/gapminder_gdp_oceania.csv'
    
    4 để chỉ định rằng các giá trị cột nên được sử dụng làm tiêu đề hàng.

  • Sử dụng

           gdpPercap_1952  gdpPercap_1957  gdpPercap_1962  gdpPercap_1967  \
    count        2.000000        2.000000        2.000000        2.000000
    mean     10298.085650    11598.522455    12696.452430    14495.021790
    std        365.560078      917.644806      677.727301       43.986086
    min      10039.595640    10949.649590    12217.226860    14463.918930
    25%      10168.840645    11274.086022    12456.839645    14479.470360
    50%      10298.085650    11598.522455    12696.452430    14495.021790
    75%      10427.330655    11922.958888    12936.065215    14510.573220
    max      10556.575660    12247.395320    13175.678000    14526.124650
    
           gdpPercap_1972  gdpPercap_1977  gdpPercap_1982  gdpPercap_1987  \
    count         2.00000        2.000000        2.000000        2.000000
    mean      16417.33338    17283.957605    18554.709840    20448.040160
    std         525.09198     1485.263517     1304.328377     2037.668013
    min       16046.03728    16233.717700    17632.410400    19007.191290
    25%       16231.68533    16758.837652    18093.560120    19727.615725
    50%       16417.33338    17283.957605    18554.709840    20448.040160
    75%       16602.98143    17809.077557    19015.859560    21168.464595
    max       16788.62948    18334.197510    19477.009280    21888.889030
    
           gdpPercap_1992  gdpPercap_1997  gdpPercap_2002  gdpPercap_2007
    count        2.000000        2.000000        2.000000        2.000000
    mean     20894.045885    24024.175170    26938.778040    29810.188275
    std       3578.979883     4205.533703     5301.853680     6540.991104
    min      18363.324940    21050.413770    23189.801350    25185.009110
    25%      19628.685413    22537.294470    25064.289695    27497.598692
    50%      20894.045885    24024.175170    26938.778040    29810.188275
    75%      22159.406358    25511.055870    28813.266385    32122.777857
    max      23424.766830    26997.936570    30687.754730    34435.367440
    
    4 để tìm hiểu thêm về DataFrame.

Dữ liệu dạng bảng trong Python là gì?

Tabular là một gói các mô -đun Python để làm việc với dữ liệu bảng. Đối tượng chính của nó là lớp Tabarray, một cấu trúc dữ liệu để giữ và thao tác dữ liệu bảng. Bằng cách đặt dữ liệu vào một đối tượng Tabarray, bạn sẽ nhận được một đại diện cho dữ liệu linh hoạt và mạnh mẽ hơn so với biểu diễn Python bản địa.a package of Python modules for working with tabular data. Its main object is the tabarray class, a data structure for holding and manipulating tabular data. By putting data into a tabarray object, you'll get a representation of the data that is more flexible and powerful than a native Python representation.

Thư viện Python nào được sử dụng để xử lý dữ liệu bảng?

Pandas trong Python có thể xử lý dữ liệu loại như vậy rất hoàn hảo. Sự ra đời của dữ liệu dạng bảng đã phát triển thành một thư viện đầy đủ tính năng có thể xử lý cả dữ liệu chuỗi và bảng.

Làm thế nào để bạn lập bảng dữ liệu trong Python?

Để lập bảng dữ liệu, chúng tôi chỉ cần truyền dữ liệu đến hàm bảng.Chúng ta cũng có thể lập danh sách lồng nhau đầu tiên làm đầu bảng bằng cách sử dụng một thuộc tính được gọi là tiêu đề.Kết quả của cả hai bảng được hiển thị dưới đây.pass the data to the tabulate function. We can also make the first nested list as the head of the table by using an attribute known as headers . The results of both the tables are shown below.

Thư viện Python nào được sử dụng khi dữ liệu ở định dạng bảng?

Sử dụng thư viện PANDAS để thực hiện số liệu thống kê trên dữ liệu bảng.Pandas là một thư viện Python được sử dụng rộng rãi cho số liệu thống kê, đặc biệt là trên dữ liệu bảng.Mượn nhiều tính năng từ các khung dữ liệu của R.Một bảng 2 chiều có các cột có tên và có khả năng có các loại dữ liệu khác nhau.Pandas library to do statistics on tabular data. Pandas is a widely-used Python library for statistics, particularly on tabular data. Borrows many features from R's dataframes. A 2-dimensional table whose columns have names and potentially have different data types.