Hướng dẫn python vertical interpolation - phép nội suy dọc python

Tôi đang làm việc với một trường 3D. Lưới ngang không đều và lưới dọc không đều và khác với nút này sang nút khác trong lưới ngang (do tọa độ dọc Sigma).

Show

Tôi muốn nội suy dữ liệu này trên một tọa độ dọc thông thường và ngay bây giờ, cách duy nhất tôi tìm thấy là lặp qua từng điểm ngang để thực hiện phép nội suy theo chiều dọc 1D đơn giản. Điều này rất dễ thực hiện (xem bên dưới một ví dụ đơn giản) nhưng hoàn toàn không hiệu quả (10 phút để nội suy bước một lần trong trường hợp ban đầu của tôi và tôi có hơn 10 000 bước thời gian để sau tiến bộ) #! /usr/bin/python nhập khẩu NP

## Horizontal mesh
x = range(0,300); y = range(0,200)
[X,Y] = np.meshgrid(x,y)

## Input 
z1   = np.array([0.,5.,10.,20.,50.,100.,200.,500.,1000.])
Z_in = np.zeros((z1.shape[0],X.shape[0],X.shape[1]))
for i in range(0,X.shape[0]):
  for j in range(0,X.shape[1]):
     Z_in[:,i,j]  = z1[:]
Z_in = Z_in+np.random.randint(-2,2,size=(z1.shape[0],X.shape[0],X.shape[1]))
var_in = np.random.randint(-10,10,size=(z1.shape[0],X.shape[0],X.shape[1]))

## Output
zout = np.array([0.,2.5,5.,7.5,10.,15.,20.,35.,50.,75.,100.,150.,200.,500.,1000.])
var_out = np.zeros((zout.shape[0],X.shape[0],X.shape[1]))

##Interpolation
for i in range(0,X.shape[0]):
   for j in range(0,X.shape[1]):
      var_out[:,i,j] = interpolate.interp1d(Z_in[:,i,j],var_in[:,i,j],bounds_error=False,fill_value=np.nan)(zout)

Nếu lưới dọc ban đầu của tôi thường xuyên ở mỗi điểm, sẽ dễ dàng theo bài viết trước này (http://stackoverflow.com/questions/7755871/interpolating-a-3d-array-in-python-how-to-oadoid -Những loops) nhưng trong trường hợp của tôi, tôi không thể tìm thấy một giải pháp dễ dàng. Tôi đã cố gắng sử dụng ánh xạ với một hàm:

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)

Nhưng tôi vẫn đến với lỗi Interp1d: "ValueError: Mảng X phải có chính xác một chiều." Bạn có biết bất kỳ cách nào khác để thực hiện điều này? Tôi đã thực hiện sai điều gì đó? Tôi sẽ rất vui khi có một số gợi ý khác.

Cảm ơn bạn trước.



Các khóa học qua video:
Lập trình C Java C# SQL Server PHP HTML5-CSS3-JavaScript

« Prev: Python: Tôi có thể làm gì với Python?

  • » Next: Python: Cách in có định dạng trong Python với bài toán in các thừa số nguyên tố
  • Copied !!!
    • Lập trình C Java C# SQL Server PHP HTML5-CSS3-JavaScript
    • Mục lục bài viết:
    • Giới thiệu Pandas DataFrame
    • Tạo dữ liệu gấu trúc
  • Tạo dữ liệu gấu trúc bằng từ điển
    • Tạo dữ liệu gấu trúc với danh sách
    • Tạo dữ liệu gấu trúc với Mảng NumPy
    • Tạo dữ liệu gấu trúc từ tệp
    • Truy xuất nhãn và dữ liệu
  • Pandas DataFrame Labels as Sequences
    • Dữ liệu dưới dạng Mảng NumPy
    • Loại dữ liệu
  • Dữ liệu gấu trúc
    • Truy cập và sửa đổi dữ liệu
    • Nhận dữ liệu với người truy cập
  • Thiết lập dữ liệu với trình truy cập
  • Chèn và Xóa dữ liệu
  • Chèn và xóa hàng
  • Chèn và Xóa các Cột
  • Áp dụng các phép toán số học
  • Áp dụng các hàm NumPy và SciPy
    • Sắp xếp dữ liệu gấu trúc
    • Lọc dữ liệu
    • Xác định thống kê dữ liệu
  • Xử lý dữ liệu bị thiếu
  • Tính toán với dữ liệu bị thiếu
    • Làm đầy dữ liệu bị thiếu
    • Xóa hàng và cột có dữ liệu bị thiếu
    • Lặp lại trên một dữ liệu gấu trúc
  • Làm việc với chuỗi thời gian
  • Tạo DataFrames với nhãn chuỗi thời gian
  • Phần kết luận


Lập chỉ mục và cắt lát

Lấy mẫu lại và cán

Lập kế hoạch với dữ liệu gấu trúc

  • Pandas DataFrame là gì và cách tạo một Pandas DataFrame
  • Cách truy cập, sửa đổi, thêm, sắp xếp, lọc và xóa dữ liệu
  • Cách xử lý các giá trị bị thiếu
  • Cách làm việc với dữ liệu chuỗi thời gian
  • Cách trực quan hóa dữ liệu có trong DataFrames

Bạn đã học đủ để bao quát các nguyên tắc cơ bản của DataFrames. Nếu bạn muốn tìm hiểu sâu hơn về cách làm việc với dữ liệu bằng Python , hãy xem toàn bộ các hướng dẫn về Gấu trúc .

» Next: Python: Cách in có định dạng trong Python với bài toán in các thừa số nguyên tố

Copied !!!

  • Lập trình C Java C# SQL Server PHP HTML5-CSS3-JavaScript
  • Mục lục bài viết:

Giới thiệu Pandas DataFrame

Tạo dữ liệu gấu trúc

>>> import pandas as pd

Tạo dữ liệu gấu trúc bằng từ điển

Tạo dữ liệu gấu trúc với danh sách

 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
6
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
8
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
5
Tạo dữ liệu gấu trúc với Mảng NumPyTạo dữ liệu gấu trúc từ tệpTruy xuất nhãn và dữ liệuPandas DataFrame Labels as SequencesDữ liệu dưới dạng Mảng NumPy
Loại dữ liệuDữ liệu gấu trúcTruy cập và sửa đổi dữ liệuNhận dữ liệu với người truy cậpThiết lập dữ liệu với trình truy cập
Chèn và Xóa dữ liệuChèn và xóa hàngChèn và Xóa các CộtÁp dụng các phép toán số họcÁp dụng các hàm NumPy và SciPy
Sắp xếp dữ liệu gấu trúcLọc dữ liệuXác định thống kê dữ liệuXử lý dữ liệu bị thiếuTính toán với dữ liệu bị thiếu
Làm đầy dữ liệu bị thiếuXóa hàng và cột có dữ liệu bị thiếuLặp lại trên một dữ liệu gấu trúcLàm việc với chuỗi thời gianTạo DataFrames với nhãn chuỗi thời gian
Lập chỉ mục và cắt látLấy mẫu lại và cánLập kế hoạch với dữ liệu gấu trúcĐọc thêmCác Pandas DataFrame là một cấu trúc có chứa dữ liệu hai chiều và tương ứng của nó nhãn . DataFrames được sử dụng rộng rãi trong khoa học dữ liệu , máy học , máy tính khoa học và nhiều lĩnh vực sử dụng nhiều dữ liệu khác.
DataFrames tương tự như bảng SQL hoặc bảng tính mà bạn làm việc trong Excel hoặc Calc. Trong nhiều trường hợp, DataFrame nhanh hơn, dễ sử dụng hơn và mạnh hơn bảng hoặc bảng tính vì chúng là một phần không thể thiếu của hệ sinh thái Python và NumPy .Trong hướng dẫn này, bạn sẽ học:Cách nhanh chóng trực quan hóa dữ liệuĐã đến lúc bắt đầu với Pandas DataFrames!Pandas DataFrames là cấu trúc dữ liệu chứa:

Dữ liệu được tổ chức theo hai thứ nguyên , hàng và cột

Bây giờ bạn có mọi thứ bạn cần để tạo Pandas DataFrame.

Có một số cách để tạo Pandas DataFrame. Trong hầu hết các trường hợp, bạn sẽ sử dụng hàm 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
21tạo và cung cấp dữ liệu, nhãn và thông tin khác. Bạn có thể chuyển dữ liệu dưới dạng danh sách hai chiều , bộ tuple hoặc mảng NumPy . Bạn cũng có thể chuyển nó dưới dạng từ điển hoặc phiên bản Pandas
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
22 hoặc là một trong một số kiểu dữ liệu khác không được đề cập trong hướng dẫn này.

Đối với ví dụ này, giả sử bạn đang sử dụng từ điển để chuyển dữ liệu:

>>>

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
23là một biến Python đề cập đến từ điển chứa dữ liệu ứng viên của bạn. Nó cũng chứa các nhãn của các cột:

  • def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    24
  • def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    25
  • def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    26
  • def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    27

Cuối cùng, 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
28đề cập đến một danh sách có chứa nhãn của các hàng, là các số từ 
>>> cities[102]
'Toronto'
0đến 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
10.

Bây giờ bạn đã sẵn sàng để tạo Pandas DataFrame:

>>>

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
23là một biến Python đề cập đến từ điển chứa dữ liệu ứng viên của bạn. Nó cũng chứa các nhãn của các cột:

  • Cuối cùng, 
    def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    28đề cập đến một danh sách có chứa nhãn của các hàng, là các số từ 
    >>> cities[102]
    'Toronto'
    
    0đến 
    def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    10.
  • Bây giờ bạn đã sẵn sàng để tạo Pandas DataFrame:
  • Đó là nó! 
    def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    31là một biến chứa tham chiếu đến Pandas DataFrame của bạn. Pandas DataFrame này trông giống như bảng ứng cử viên ở trên và có các tính năng sau:

Các nhãn hàng từ 

>>> cities[102]
'Toronto'
0đến
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
10

Hướng dẫn python vertical interpolation - phép nội suy dọc python

Cột nhãn như 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
24, 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
25, 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
26, và
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
27

Dữ liệu như tên ứng viên, thành phố, độ tuổi và điểm kiểm tra Python

>>>

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
23là một biến Python đề cập đến từ điển chứa dữ liệu ứng viên của bạn. Nó cũng chứa các nhãn của các cột:

Cuối cùng, 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
28đề cập đến một danh sách có chứa nhãn của các hàng, là các số từ 
>>> cities[102]
'Toronto'
0đến 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
10.

Bây giờ bạn đã sẵn sàng để tạo Pandas DataFrame:

>>>

>>> cities = df['city']
>>> cities
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
23là một biến Python đề cập đến từ điển chứa dữ liệu ứng viên của bạn. Nó cũng chứa các nhãn của các cột:

Cuối cùng, 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
28đề cập đến một danh sách có chứa nhãn của các hàng, là các số từ 
>>> cities[102]
'Toronto'
0đến 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
10.

>>>

>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
23là một biến Python đề cập đến từ điển chứa dữ liệu ứng viên của bạn. Nó cũng chứa các nhãn của các cột:

Cuối cùng, 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
28đề cập đến một danh sách có chứa nhãn của các hàng, là các số từ 
>>> cities[102]
'Toronto'
0đến 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
10.

Hướng dẫn python vertical interpolation - phép nội suy dọc python

Bây giờ bạn đã sẵn sàng để tạo Pandas DataFrame:

>>>

>>> cities[102]
'Toronto'

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
23là một biến Python đề cập đến từ điển chứa dữ liệu ứng viên của bạn. Nó cũng chứa các nhãn của các cột:

Cuối cùng, 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
28đề cập đến một danh sách có chứa nhãn của các hàng, là các số từ 
>>> cities[102]
'Toronto'
0đến 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
10.

>>>

>>> df.loc[103]
name          Jana
city        Prague
age             33
py-score        81
Name: 103, dtype: object

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
23là một biến Python đề cập đến từ điển chứa dữ liệu ứng viên của bạn. Nó cũng chứa các nhãn của các cột:

Hướng dẫn python vertical interpolation - phép nội suy dọc python

Cuối cùng, 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
28đề cập đến một danh sách có chứa nhãn của các hàng, là các số từ 
>>> cities[102]
'Toronto'
0đến 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
10.

Bây giờ bạn đã sẵn sàng để tạo Pandas DataFrame:

Đó là nó! 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31là một biến chứa tham chiếu đến Pandas DataFrame của bạn. Pandas DataFrame này trông giống như bảng ứng cử viên ở trên và có các tính năng sau:

  • Các nhãn hàng từ 
    >>> cities[102]
    'Toronto'
    
    0đến
    def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    10
  • Cột nhãn như 
    def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    24, 
    def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    25, 
    def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    26, và
    def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    27
  • Dữ liệu như tên ứng viên, thành phố, độ tuổi và điểm kiểm tra Python
  • Hình này cho thấy các nhãn và dữ liệu từ 
    def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    31:

Các nhãn hàng được viền màu xanh lam, trong khi các nhãn cột được viền màu đỏ và các giá trị dữ liệu được viền màu tím.

Pandas DataFrames đôi khi có thể rất lớn, khiến việc xem xét tất cả các hàng cùng một lúc là không thực tế. Bạn có thể sử dụng 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
39để hiển thị một số mục đầu tiên và 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
40để hiển thị một số mục cuối cùng:

>>>

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
0

Đó là cách bạn có thể hiển thị chỉ phần đầu hoặc phần cuối của Pandas DataFrame. Tham số 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
41chỉ định số hàng sẽ hiển thị.

Lưu ý: Có thể hữu ích khi coi Pandas DataFrame như một từ điển gồm các cột, hoặc Chuỗi Pandas, với nhiều tính năng bổ sung.

Bạn có thể truy cập một cột trong Pandas DataFrame giống như cách bạn lấy giá trị từ từ điển:

>>>

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
1

Đây là cách thuận tiện nhất để lấy một cột từ Pandas DataFrame.

Có thể kiểm soát thứ tự của các cột bằng 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
53tham số và nhãn hàng bằng 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
54:

>>>

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
2

Như bạn thấy, bạn đã chỉ định các nhãn hàng 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
55, 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
56và 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
57. Bạn tôi cũng đã buộc phải theo thứ tự của cột: 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
58, 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
59, 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
60.

Tạo dữ liệu gấu trúc với danh sách

Một cách khác để tạo Pandas DataFrame là sử dụng danh sách các từ điển:

>>>

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
3

Như bạn thấy, bạn đã chỉ định các nhãn hàng 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
55, 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
56và 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
57. Bạn tôi cũng đã buộc phải theo thứ tự của cột: 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
58, 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
59, 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
60.

Tạo dữ liệu gấu trúc với danh sách

>>>

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
4

Như bạn thấy, bạn đã chỉ định các nhãn hàng 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
55, 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
56và 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
57. Bạn tôi cũng đã buộc phải theo thứ tự của cột: 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
58, 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
59, 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
60.

Tạo dữ liệu gấu trúc với danh sách

Một cách khác để tạo Pandas DataFrame là sử dụng danh sách các từ điển:

>>>

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
5

Một lần nữa, khóa từ điển là nhãn cột và giá trị từ điển là giá trị dữ liệu trong DataFrame.

Bạn cũng có thể sử dụng danh sách lồng nhau hoặc danh sách các danh sách làm giá trị dữ liệu. Nếu bạn làm vậy, thì nên chỉ định rõ ràng các nhãn của cột, hàng hoặc cả hai khi bạn tạo DataFrame:

>>>

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
6

Đó là cách bạn có thể sử dụng danh sách lồng nhau để tạo Pandas DataFrame. Bạn cũng có thể sử dụng danh sách các bộ giá trị theo cách tương tự. Để làm như vậy, chỉ cần thay thế các danh sách lồng nhau trong ví dụ trên bằng các bộ giá trị.

Tạo dữ liệu gấu trúc với Mảng NumPy

Bạn có thể truyền mảng NumPy hai chiều cho hàm 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
21tạo giống như cách bạn làm với danh sách:

Mặc dù ví dụ này trông gần giống với cách triển khai danh sách lồng nhau ở trên, nhưng nó có một ưu điểm: Bạn có thể chỉ định tham số tùy chọn def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout) Zout = np.zeros((X.shape[0],X.shape[1])) for l in range(0,zout.shape[0]): Zout[:,:] = zout[l] var_out[l] = map(interp_perso,Z_in,var_in,Zout) 62.

Khi 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
62được đặt thành 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
64(cài đặt mặc định), dữ liệu từ mảng NumPy sẽ không được sao chép. Điều này có nghĩa là dữ liệu gốc từ mảng được gán cho Pandas DataFrame. Nếu bạn sửa đổi mảng, thì DataFrame của bạn cũng sẽ thay đổi:

Như bạn có thể thấy, khi bạn thay đổi mục đầu tiên 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
65, bạn cũng sửa đổi 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
66.

>>>

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
7

Lưu ý: Việc không sao chép các giá trị dữ liệu có thể giúp bạn tiết kiệm đáng kể thời gian và sức mạnh xử lý khi làm việc với các tập dữ liệu lớn.

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
8

Nếu hành vi này không phải là những gì bạn muốn, thì bạn nên chỉ định 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
67trong hàm 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
21tạo. Bằng cách đó, 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
66sẽ được tạo với một bản sao của các giá trị từ 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
65thay vì các giá trị thực tế.

>>>

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
9

Tạo dữ liệu gấu trúc từ tệp

Bạn có thể lưu và tải dữ liệu và nhãn từ Pandas DataFrame đến và từ một số loại tệp, bao gồm CSV, Excel, SQL, JSON, v.v. Đây là một tính năng rất mạnh mẽ.

Bạn có thể lưu DataFrame ứng viên công việc của mình vào tệp CSV với 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
71:

  • Câu lệnh trên sẽ tạo ra một tệp CSV được gọi 
    def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    72trong thư mục làm việc của bạn:
  • Giờ bạn đã có tệp CSV chứa dữ liệu, bạn có thể tải tệp đó bằng 
    def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    73:
  • Đó là cách bạn lấy Pandas DataFrame từ một tệp. Trong trường hợp này, 
    def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    74chỉ định rằng các nhãn hàng nằm trong cột đầu tiên của tệp CSV.
  • Truy xuất nhãn và dữ liệu

Bây giờ bạn đã tạo DataFrame của mình, bạn có thể bắt đầu truy xuất thông tin từ nó. Với Pandas, bạn có thể thực hiện các hành động sau:

Truy xuất và sửa đổi nhãn hàng và cột dưới dạng chuỗi

>>>

>>> import pandas as pd
0

Biểu diễn dữ liệu dưới dạng mảng NumPy

>>>

>>> import pandas as pd
1

Kiểm tra và điều chỉnh các loại dữ liệu

Phân tích kích thước của 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
21các đối tượng

>>>

>>> import pandas as pd
2

Pandas DataFrame Labels as Sequences

Bạn có thể lấy nhãn hàng của DataFrame với 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
76và nhãn cột của nó với 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
77:

Bây giờ bạn có nhãn hàng và cột là các loại chuỗi đặc biệt. Như bạn có thể làm với bất kỳ chuỗi Python nào khác, bạn có thể nhận được một mục duy nhất:

Ngoài việc trích xuất một mục cụ thể, bạn có thể áp dụng các thao tác trình tự khác, bao gồm cả việc lặp qua các nhãn của hàng hoặc cột. Tuy nhiên, điều này hiếm khi cần thiết vì Pandas cung cấp các cách khác để lặp qua DataFrames mà bạn sẽ thấy trong phần sau .

>>>

>>> import pandas as pd
3

Bạn cũng có thể sử dụng phương pháp này để sửa đổi các nhãn:

Hướng dẫn python vertical interpolation - phép nội suy dọc python

Tài liệu Pandas đề xuất sử dụng 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
85vì tính linh hoạt được cung cấp bởi hai tham số tùy chọn:

  1. def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    90: Sử dụng tham số này để chỉ định kiểu dữ liệu của mảng kết quả. Nó được đặt thành 
    def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    91theo mặc định.
  2. def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    62: Đặt tham số này thành 
    def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    64nếu bạn muốn sử dụng dữ liệu gốc từ DataFrame. Đặt nó thành 
    def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    94nếu bạn muốn tạo một bản sao dữ liệu.

Tuy nhiên, nó 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
86đã tồn tại lâu hơn nhiều so với 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
85những gì đã được giới thiệu trong phiên bản Pandas 0.24.0. Điều đó có nghĩa là bạn có thể sẽ thấy 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
86thường xuyên hơn, đặc biệt là trong mã cũ hơn.

Loại dữ liệu

Các loại các giá trị dữ liệu , hay còn gọi là kiểu dữ liệu hoặc dtypes , rất quan trọng vì họ xác định dung lượng bộ nhớ sử dụng DataFrame của bạn, cũng như tốc độ tính toán của nó và mức độ chính xác.

Gấu trúc phụ thuộc rất nhiều vào kiểu dữ liệu NumPy . Tuy nhiên, Pandas 1.0 đã giới thiệu một số loại bổ sung:

  • def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    98và 
    def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    99hỗ trợ các giá trị Boolean bị thiếu và lôgic ba giá trị Kleene .
  • >>> import pandas as pd
    
    00và 
    >>> import pandas as pd
    
    01đại diện cho một loại chuỗi chuyên dụng.

Bạn có thể lấy các kiểu dữ liệu cho từng cột của Pandas DataFrame bằng 

>>> import pandas as pd
02:

>>>

>>> import pandas as pd
4

Như bạn có thể thấy, 

>>> import pandas as pd
02trả về một 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
22đối tượng có tên cột làm nhãn và kiểu dữ liệu tương ứng dưới dạng giá trị.

Nếu bạn muốn sửa đổi kiểu dữ liệu của một hoặc nhiều cột, thì bạn có thể sử dụng 

>>> import pandas as pd
05:

>>>

>>> import pandas as pd
5

Như bạn có thể thấy, 

>>> import pandas as pd
02trả về một 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
22đối tượng có tên cột làm nhãn và kiểu dữ liệu tương ứng dưới dạng giá trị.

Nếu bạn muốn sửa đổi kiểu dữ liệu của một hoặc nhiều cột, thì bạn có thể sử dụng 

>>> import pandas as pd
05:

Tham số bắt buộc quan trọng nhất và duy nhất của >>> import pandas as pd 05là def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout) Zout = np.zeros((X.shape[0],X.shape[1])) for l in range(0,zout.shape[0]): Zout[:,:] = zout[l] var_out[l] = map(interp_perso,Z_in,var_in,Zout) 90. Nó mong đợi một kiểu dữ liệu hoặc từ điển. Nếu bạn chuyển từ điển, thì các khóa là tên cột và các giá trị là kiểu dữ liệu tương ứng mong muốn của bạn.

Như bạn có thể thấy, các kiểu dữ liệu cho các cột 

>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
8và 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
5trong DataFrame 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31đều 
>>> import pandas as pd
11, đại diện cho 64-bit (hoặc 8-byte) số nguyên. Tuy nhiên, 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
66cũng cung cấp một kiểu dữ liệu số nguyên 32 bit (4 byte) nhỏ hơn được gọi 
>>> import pandas as pd
13.

>>>

>>> import pandas as pd
6

Như bạn có thể thấy, 

>>> import pandas as pd
02trả về một 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
22đối tượng có tên cột làm nhãn và kiểu dữ liệu tương ứng dưới dạng giá trị.

Nếu bạn muốn sửa đổi kiểu dữ liệu của một hoặc nhiều cột, thì bạn có thể sử dụng 

>>> import pandas as pd
05:

Tham số bắt buộc quan trọng nhất và duy nhất của 

>>> import pandas as pd
05là 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
90. Nó mong đợi một kiểu dữ liệu hoặc từ điển. Nếu bạn chuyển từ điển, thì các khóa là tên cột và các giá trị là kiểu dữ liệu tương ứng mong muốn của bạn.

>>>

>>> import pandas as pd
7

Như bạn có thể thấy, 

>>> import pandas as pd
02trả về một 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
22đối tượng có tên cột làm nhãn và kiểu dữ liệu tương ứng dưới dạng giá trị.

Nếu bạn muốn sửa đổi kiểu dữ liệu của một hoặc nhiều cột, thì bạn có thể sử dụng 

>>> import pandas as pd
05:

Tham số bắt buộc quan trọng nhất và duy nhất của >>> import pandas as pd 05là def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout) Zout = np.zeros((X.shape[0],X.shape[1])) for l in range(0,zout.shape[0]): Zout[:,:] = zout[l] var_out[l] = map(interp_perso,Z_in,var_in,Zout) 90. Nó mong đợi một kiểu dữ liệu hoặc từ điển. Nếu bạn chuyển từ điển, thì các khóa là tên cột và các giá trị là kiểu dữ liệu tương ứng mong muốn của bạn.

Như bạn có thể thấy, các kiểu dữ liệu cho các cột 

>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
8và 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
5trong DataFrame 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31đều 
>>> import pandas as pd
11, đại diện cho 64-bit (hoặc 8-byte) số nguyên. Tuy nhiên, 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
66cũng cung cấp một kiểu dữ liệu số nguyên 32 bit (4 byte) nhỏ hơn được gọi 
>>> import pandas as pd
13.

>>>

>>> import pandas as pd
8

Như bạn có thể thấy, 

>>> import pandas as pd
02trả về một 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
22đối tượng có tên cột làm nhãn và kiểu dữ liệu tương ứng dưới dạng giá trị.

Nếu bạn muốn sửa đổi kiểu dữ liệu của một hoặc nhiều cột, thì bạn có thể sử dụng >>> import pandas as pd 05:

Tham số bắt buộc quan trọng nhất và duy nhất của 

>>> import pandas as pd
05là 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
90. Nó mong đợi một kiểu dữ liệu hoặc từ điển. Nếu bạn chuyển từ điển, thì các khóa là tên cột và các giá trị là kiểu dữ liệu tương ứng mong muốn của bạn.

>>>

>>> import pandas as pd
9

Như bạn có thể thấy, 

>>> import pandas as pd
02trả về một 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
22đối tượng có tên cột làm nhãn và kiểu dữ liệu tương ứng dưới dạng giá trị.

Tổng cộng Pandas có bốn người truy cập:

  1. def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)
    
    Zout =  np.zeros((X.shape[0],X.shape[1]))
    for l in range(0,zout.shape[0]):
       Zout[:,:] = zout[l]
       var_out[l] = map(interp_perso,Z_in,var_in,Zout)
    
    47chấp nhận các nhãn của hàng và cột và trả về Chuỗi hoặc Dữ liệu. Bạn có thể sử dụng nó để lấy toàn bộ hàng hoặc cột, cũng như các phần của chúng.

  2. >>> import pandas as pd
    
    38chấp nhận các chỉ số dựa trên 0 của các hàng và cột và trả về Series hoặc DataFrames. Bạn có thể sử dụng nó để lấy toàn bộ hàng hoặc cột hoặc các phần của chúng.

  3. >>> import pandas as pd
    
    46 chấp nhận nhãn của các hàng và cột và trả về một giá trị dữ liệu duy nhất.

  4. >>> import pandas as pd
    
    47 chấp nhận các chỉ số dựa trên 0 của các hàng và cột và trả về một giá trị dữ liệu duy nhất.

Trong số này, 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
47và 
>>> import pandas as pd
38đặc biệt mạnh mẽ. Chúng hỗ trợ cắt và lập chỉ mục kiểu NumPy . Bạn có thể sử dụng chúng để truy cập một cột:

>>>

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
0

>>> import pandas as pd
50trả về cột 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7. Cấu trúc lát cắt ( 
>>> import pandas as pd
52) ở vị trí nhãn hàng có nghĩa là tất cả các hàng phải được đưa vào. 
>>> import pandas as pd
53trả về cùng một cột vì chỉ mục dựa trên 0 
>>> import pandas as pd
22tham chiếu đến cột thứ hai 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7,.

Cũng giống như bạn có thể làm với NumPy, bạn có thể cung cấp các lát cùng với danh sách hoặc mảng thay vì chỉ số để có nhiều hàng hoặc cột:

>>>

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
1

>>> import pandas as pd
50trả về cột 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7. Cấu trúc lát cắt ( 
>>> import pandas as pd
52) ở vị trí nhãn hàng có nghĩa là tất cả các hàng phải được đưa vào. 
>>> import pandas as pd
53trả về cùng một cột vì chỉ mục dựa trên 0 
>>> import pandas as pd
22tham chiếu đến cột thứ hai 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7,.

  • Cũng giống như bạn có thể làm với NumPy, bạn có thể cung cấp các lát cùng với danh sách hoặc mảng thay vì chỉ số để có nhiều hàng hoặc cột:
  • Trong ví dụ này, bạn sử dụng:

Lát để lấy các hàng có nhãn 

>>> import pandas as pd
56thông qua 
>>> import pandas as pd
57, tương đương với các chỉ số 
>>> import pandas as pd
22thông qua
>>> import pandas as pd
59

Liệt kê để lấy các cột 

>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
6và 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7tương đương với các chỉ số 
>>> import pandas as pd
42và
>>> import pandas as pd
22

Cả hai câu lệnh đều trả về một Pandas DataFrame với giao của năm hàng và hai cột mong muốn.

Điều này dẫn đến sự khác biệt rất quan trọng giữa 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
47và 
>>> import pandas as pd
38. Như bạn có thể nhìn thấy từ ví dụ trước, khi bạn vượt qua các nhãn hàng 
>>> import pandas as pd
66để 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
47, bạn sẽ có được các hàng 
>>> import pandas as pd
56thông qua 
>>> import pandas as pd
57. Tuy nhiên, khi bạn chuyển chỉ số hàng 
>>> import pandas as pd
70đến 
>>> import pandas as pd
38, bạn chỉ nhận được các hàng có chỉ số 
>>> import pandas as pd
22đi qua 
>>> import pandas as pd
59.

>>>

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
2

>>> import pandas as pd
50trả về cột 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7. Cấu trúc lát cắt ( 
>>> import pandas as pd
52) ở vị trí nhãn hàng có nghĩa là tất cả các hàng phải được đưa vào. 
>>> import pandas as pd
53trả về cùng một cột vì chỉ mục dựa trên 0 
>>> import pandas as pd
22tham chiếu đến cột thứ hai 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7,.

Cũng giống như bạn có thể làm với NumPy, bạn có thể cung cấp các lát cùng với danh sách hoặc mảng thay vì chỉ số để có nhiều hàng hoặc cột:

>>>

>>> import pandas as pd
50trả về cột 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7. Cấu trúc lát cắt ( 
>>> import pandas as pd
52) ở vị trí nhãn hàng có nghĩa là tất cả các hàng phải được đưa vào. 
>>> import pandas as pd
53trả về cùng một cột vì chỉ mục dựa trên 0 
>>> import pandas as pd
22tham chiếu đến cột thứ hai 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7,.

Cũng giống như bạn có thể làm với NumPy, bạn có thể cung cấp các lát cùng với danh sách hoặc mảng thay vì chỉ số để có nhiều hàng hoặc cột:

Trong ví dụ này, bạn sử dụng:

>>>

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
4

>>> import pandas as pd
50trả về cột 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7. Cấu trúc lát cắt ( 
>>> import pandas as pd
52) ở vị trí nhãn hàng có nghĩa là tất cả các hàng phải được đưa vào. 
>>> import pandas as pd
53trả về cùng một cột vì chỉ mục dựa trên 0 
>>> import pandas as pd
22tham chiếu đến cột thứ hai 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7,.

Cũng giống như bạn có thể làm với NumPy, bạn có thể cung cấp các lát cùng với danh sách hoặc mảng thay vì chỉ số để có nhiều hàng hoặc cột:

Trong ví dụ này, bạn sử dụng:

>>>

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
5

>>> import pandas as pd
50trả về cột 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7. Cấu trúc lát cắt ( 
>>> import pandas as pd
52) ở vị trí nhãn hàng có nghĩa là tất cả các hàng phải được đưa vào. 
>>> import pandas as pd
53trả về cùng một cột vì chỉ mục dựa trên 0 
>>> import pandas as pd
22tham chiếu đến cột thứ hai 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7,.

Cũng giống như bạn có thể làm với NumPy, bạn có thể cung cấp các lát cùng với danh sách hoặc mảng thay vì chỉ số để có nhiều hàng hoặc cột:

>>>

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
6

>>> import pandas as pd
50trả về cột 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7. Cấu trúc lát cắt ( 
>>> import pandas as pd
52) ở vị trí nhãn hàng có nghĩa là tất cả các hàng phải được đưa vào. 
>>> import pandas as pd
53trả về cùng một cột vì chỉ mục dựa trên 0 
>>> import pandas as pd
22tham chiếu đến cột thứ hai 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7,.

Cũng giống như bạn có thể làm với NumPy, bạn có thể cung cấp các lát cùng với danh sách hoặc mảng thay vì chỉ số để có nhiều hàng hoặc cột:

Trong ví dụ này, bạn sử dụng:

Chèn và xóa hàng

Hãy tưởng tượng bạn muốn thêm một người mới vào danh sách ứng viên tuyển dụng của mình. Bạn có thể bắt đầu bằng cách tạo một 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
22đối tượng mới đại diện cho ứng cử viên mới này:

>>>

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
7

Đối tượng mới có các nhãn tương ứng với các nhãn cột từ 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31. Đó là lý do tại sao bạn cần 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
02.

Bạn có thể thêm 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
03dưới dạng một hàng mới vào cuối 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31bằng 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
05:

>>>

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
8

Đối tượng mới có các nhãn tương ứng với các nhãn cột từ 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31. Đó là lý do tại sao bạn cần 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
02.

Bạn có thể thêm 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
03dưới dạng một hàng mới vào cuối 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31bằng 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
05:

>>>

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
9

Đối tượng mới có các nhãn tương ứng với các nhãn cột từ 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31. Đó là lý do tại sao bạn cần 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
02.

Bạn có thể thêm >>> data = { ... 'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'], ... 'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai', ... 'Manchester', 'Cairo', 'Osaka'], ... 'age': [41, 28, 33, 34, 38, 31, 37], ... 'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0] ... } >>> row_labels = [101, 102, 103, 104, 105, 106, 107] 03dưới dạng một hàng mới vào cuối def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout) Zout = np.zeros((X.shape[0],X.shape[1])) for l in range(0,zout.shape[0]): Zout[:,:] = zout[l] var_out[l] = map(interp_perso,Z_in,var_in,Zout) 31bằng >>> data = { ... 'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'], ... 'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai', ... 'Manchester', 'Cairo', 'Osaka'], ... 'age': [41, 28, 33, 34, 38, 31, 37], ... 'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0] ... } >>> row_labels = [101, 102, 103, 104, 105, 106, 107] 05:

Tại đây, 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
05trả về Pandas DataFrame với hàng mới được thêm vào. Lưu ý cách Pandas sử dụng thuộc tính 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
07, là giá trị 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
08, để chỉ định nhãn cho hàng mới.

>>>

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
0

Đối tượng mới có các nhãn tương ứng với các nhãn cột từ 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31. Đó là lý do tại sao bạn cần 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
02.

Bạn có thể thêm 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
03dưới dạng một hàng mới vào cuối 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31bằng 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
05:

>>>

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
1

Đối tượng mới có các nhãn tương ứng với các nhãn cột từ 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31. Đó là lý do tại sao bạn cần 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
02.

Bạn có thể thêm 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
03dưới dạng một hàng mới vào cuối 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31bằng 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
05:

>>>

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
2

Đối tượng mới có các nhãn tương ứng với các nhãn cột từ 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31. Đó là lý do tại sao bạn cần 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
02.

Bạn có thể thêm 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
03dưới dạng một hàng mới vào cuối 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31bằng 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
05:

>>>

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
3

Đối tượng mới có các nhãn tương ứng với các nhãn cột từ 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31. Đó là lý do tại sao bạn cần 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
02.

Bạn có thể thêm 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
03dưới dạng một hàng mới vào cuối 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31bằng 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
05:

>>>

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
4

Tại đây, 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
05trả về Pandas DataFrame với hàng mới được thêm vào. Lưu ý cách Pandas sử dụng thuộc tính 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
07, là giá trị 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
08, để chỉ định nhãn cho hàng mới.

Bạn đã thêm một hàng mới với một lệnh gọi đến 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
05và bạn có thể xóa hàng đó bằng một lệnh gọi tới 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
10:

Tại đây, >>> data = { ... 'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'], ... 'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai', ... 'Manchester', 'Cairo', 'Osaka'], ... 'age': [41, 28, 33, 34, 38, 31, 37], ... 'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0] ... } >>> row_labels = [101, 102, 103, 104, 105, 106, 107] 10xóa các hàng được chỉ định với tham số >>> data = { ... 'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'], ... 'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai', ... 'Manchester', 'Cairo', 'Osaka'], ... 'age': [41, 28, 33, 34, 38, 31, 37], ... 'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0] ... } >>> row_labels = [101, 102, 103, 104, 105, 106, 107] 12. Theo mặc định, nó trả về Pandas DataFrame với các hàng được chỉ định đã bị xóa. Nếu bạn vượt qua >>> data = { ... 'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'], ... 'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai', ... 'Manchester', 'Cairo', 'Osaka'], ... 'age': [41, 28, 33, 34, 38, 31, 37], ... 'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0] ... } >>> row_labels = [101, 102, 103, 104, 105, 106, 107] 13, thì DataFrame ban đầu sẽ được sửa đổi và bạn sẽ nhận được def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout) Zout = np.zeros((X.shape[0],X.shape[1])) for l in range(0,zout.shape[0]): Zout[:,:] = zout[l] var_out[l] = map(interp_perso,Z_in,var_in,Zout) 91dưới dạng giá trị trả về.

Chèn và Xóa các Cột

>>>

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
5

Cách đơn giản nhất để chèn một cột trong Pandas DataFrame là làm theo cùng một quy trình mà bạn sử dụng khi thêm một mục vào từ điển . Đây là cách bạn có thể thêm một cột chứa điểm của ứng viên của bạn trong một bài kiểm tra JavaScript :

>>>

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
6

Bây giờ DataFrame ban đầu có thêm một cột 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
15, ở cuối.

Bạn không cần phải cung cấp một chuỗi giá trị đầy đủ. Bạn có thể thêm một cột mới với một giá trị duy nhất:

DataFrame 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31hiện có một cột bổ sung chứa các số không.

Nếu bạn đã sử dụng từ điển trước đây, thì cách chèn cột này có thể quen thuộc với bạn. Tuy nhiên, nó không cho phép bạn chỉ định vị trí của cột mới. Nếu vị trí của cột mới là quan trọng, thì bạn có thể sử dụng 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
17thay thế:

>>>

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
7

Bạn vừa chèn một cột khác có điểm của bài kiểm tra Django . Tham số 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
18xác định vị trí hoặc chỉ mục dựa trên 0 của cột mới trong Pandas DataFrame. 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
19đặt nhãn của cột mới và 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
20chỉ định các giá trị dữ liệu để chèn.

Bạn có thể xóa một hoặc nhiều cột khỏi Pandas DataFrame giống như cách bạn làm với từ điển Python thông thường, bằng cách sử dụng 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
21câu lệnh :

>>>

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
8

Kết quả tương tự như trong ví dụ trước, nhưng ở đây bạn đã sử dụng hàm NumPy hiện có thay vì viết mã của riêng bạn.

Sắp xếp dữ liệu gấu trúc

Bạn có thể sắp xếp một Pandas DataFrame với 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
49:

>>>

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
9

Ví dụ này sắp xếp DataFrame của bạn theo các giá trị trong cột 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
15. Tham số 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
51đặt nhãn của hàng hoặc cột để sắp xếp theo. 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
52chỉ định xem bạn muốn sắp xếp theo thứ tự tăng dần ( 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
94) hay giảm dần ( 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
64), thứ tự sau là cài đặt mặc định. Bạn có thể vượt qua 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
55để chọn nếu bạn muốn sắp xếp hàng ( 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
56) hoặc cột ( 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
29).

Nếu bạn muốn sắp xếp theo nhiều cột, thì chỉ cần chuyển danh sách làm đối số cho 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
51và 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
52:

>>>

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
0

Trong trường hợp này, DataFrame được sắp xếp theo cột 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
35, nhưng nếu hai giá trị giống nhau, thì thứ tự của chúng được xác định bởi các giá trị từ cột 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
5.

Tham số tùy chọn 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
62cũng có thể được sử dụng với 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
49. Nó được đặt thành 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
64theo mặc định, đảm bảo 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
49trả về một Pandas DataFrame mới. Khi bạn đặt 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
13, DataFrame hiện có sẽ được sửa đổi và 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
49sẽ trở lại 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
91.

Nếu bạn đã từng cố gắng sắp xếp các giá trị trong Excel , thì bạn có thể thấy cách tiếp cận Pandas hiệu quả và tiện lợi hơn nhiều. Khi bạn có một lượng lớn dữ liệu, Pandas có thể vượt trội hơn đáng kể so với Excel.

Để biết thêm thông tin về cách sắp xếp trong Gấu trúc, hãy xem Sắp xếp theo gấu trúc: Hướng dẫn sắp xếp dữ liệu bằng Python của bạn .

Lọc dữ liệu

Lọc dữ liệu là một tính năng mạnh mẽ khác của Pandas. Nó hoạt động tương tự như lập chỉ mục với mảng Boolean trong NumPy .

Nếu bạn áp dụng một số hoạt động logic trên một 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
22đối tượng, thì bạn sẽ nhận được một Chuỗi khác với các giá trị Boolean 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
94và 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
64:

>>>

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
1

Trong trường hợp này, 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
72trả về 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
94cho những hàng có điểm Django lớn hơn hoặc bằng 80. Nó trả về 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
64cho những hàng có điểm Django nhỏ hơn 80.

Bây giờ bạn có Chuỗi 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
75chứa đầy dữ liệu Boolean. Biểu thức 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
76trả về một Pandas DataFrame với các hàng từ 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
31đó tương ứng với 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
94trong 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
75:

>>>

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
2

Như bạn có thể thấy, 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
80, 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
81, 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
82, và 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
83là 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
94, do đó 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
76chứa các hàng với các nhãn này. Mặt khác, 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
86, 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
87, và 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
88là 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
64, vì vậy các hàng tương ứng không xuất hiện trong 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
76.

Bạn có thể tạo các biểu thức rất mạnh mẽ và phức tạp bằng cách kết hợp các phép toán logic với các toán tử sau:

  • >>> data = {
    ...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
    ...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
    ...              'Manchester', 'Cairo', 'Osaka'],
    ...     'age': [41, 28, 33, 34, 38, 31, 37],
    ...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
    ... }
    
    >>> row_labels = [101, 102, 103, 104, 105, 106, 107]
    
    91( 
    >>> data = {
    ...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
    ...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
    ...              'Manchester', 'Cairo', 'Osaka'],
    ...     'age': [41, 28, 33, 34, 38, 31, 37],
    ...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
    ... }
    
    >>> row_labels = [101, 102, 103, 104, 105, 106, 107]
    
    92)
  • >>> data = {
    ...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
    ...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
    ...              'Manchester', 'Cairo', 'Osaka'],
    ...     'age': [41, 28, 33, 34, 38, 31, 37],
    ...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
    ... }
    
    >>> row_labels = [101, 102, 103, 104, 105, 106, 107]
    
    93( 
    >>> data = {
    ...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
    ...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
    ...              'Manchester', 'Cairo', 'Osaka'],
    ...     'age': [41, 28, 33, 34, 38, 31, 37],
    ...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
    ... }
    
    >>> row_labels = [101, 102, 103, 104, 105, 106, 107]
    
    94)
  • >>> data = {
    ...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
    ...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
    ...              'Manchester', 'Cairo', 'Osaka'],
    ...     'age': [41, 28, 33, 34, 38, 31, 37],
    ...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
    ... }
    
    >>> row_labels = [101, 102, 103, 104, 105, 106, 107]
    
    95( 
    >>> data = {
    ...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
    ...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
    ...              'Manchester', 'Cairo', 'Osaka'],
    ...     'age': [41, 28, 33, 34, 38, 31, 37],
    ...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
    ... }
    
    >>> row_labels = [101, 102, 103, 104, 105, 106, 107]
    
    96)
  • >>> data = {
    ...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
    ...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
    ...              'Manchester', 'Cairo', 'Osaka'],
    ...     'age': [41, 28, 33, 34, 38, 31, 37],
    ...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
    ... }
    
    >>> row_labels = [101, 102, 103, 104, 105, 106, 107]
    
    97( 
    >>> data = {
    ...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
    ...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
    ...              'Manchester', 'Cairo', 'Osaka'],
    ...     'age': [41, 28, 33, 34, 38, 31, 37],
    ...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
    ... }
    
    >>> row_labels = [101, 102, 103, 104, 105, 106, 107]
    
    98)

Ví dụ: bạn có thể nhận được DataFrame với các ứng viên có 

>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
5và 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
15lớn hơn hoặc bằng 80:

>>>

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
3

Biểu thức 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
01trả về một Chuỗi có 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
94trong các hàng có cả hai 
>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
5và 
>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
15lớn hơn hoặc bằng 80 và 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
64các hàng khác. Trong trường hợp này, chỉ các hàng có nhãn 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
06và 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
80thỏa mãn cả hai điều kiện.

Bạn cũng có thể áp dụng các quy trình logic NumPy thay vì các toán tử.

Đối với một số thao tác yêu cầu lọc dữ liệu, sẽ thuận tiện hơn khi sử dụng 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
08. Nó thay thế các giá trị ở các vị trí mà điều kiện đã cung cấp không được thỏa mãn:

>>>

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
4

Trong ví dụ này, điều kiện là 

>>> data = {
...     'name': ['Xavier', 'Ann', 'Jana', 'Yi', 'Robin', 'Amal', 'Nori'],
...     'city': ['Mexico City', 'Toronto', 'Prague', 'Shanghai',
...              'Manchester', 'Cairo', 'Osaka'],
...     'age': [41, 28, 33, 34, 38, 31, 37],
...     'py-score': [88.0, 79.0, 81.0, 80.0, 68.0, 61.0, 84.0]
... }

>>> row_labels = [101, 102, 103, 104, 105, 106, 107]
72. Các giá trị của DataFrame hoặc Chuỗi 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
08sẽ được giữ nguyên khi có điều kiện 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
94và sẽ được thay thế bằng giá trị của 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
12(trong trường hợp này 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
13) khi có điều kiện 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
64.

Xác định thống kê dữ liệu

Pandas cung cấp nhiều phương pháp thống kê cho DataFrames. Bạn có thể nhận thống kê cơ bản cho các cột số của Pandas DataFrame với 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
15:

>>>

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
5

Tại đây, 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
15trả về một DataFrame mới với số hàng được chỉ định bởi 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
17, cũng như giá trị trung bình, độ lệch chuẩn, tối thiểu, tối đa và phần tư của các cột.

Nếu bạn muốn nhận thống kê cụ thể cho một số hoặc tất cả các cột của mình, thì bạn có thể gọi các phương thức như 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
18hoặc 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
19:

>>>

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
6

Khi được áp dụng cho Pandas DataFrame, các phương pháp này trả về Chuỗi với kết quả cho mỗi cột. Khi được áp dụng cho một 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
22đối tượng hoặc một cột của DataFrame, các phương thức này sẽ trả về giá trị vô hướng .

Để tìm hiểu thêm về tính toán thống kê với Gấu trúc, hãy xem Thống kê mô tả với Python và NumPy, SciPy và Pandas: Tương quan với Python .

Xử lý dữ liệu bị thiếu

Dữ liệu bị thiếu là rất phổ biến trong khoa học dữ liệu và học máy. Nhưng đừng bao giờ sợ hãi! Pandas có các tính năng rất mạnh để làm việc với dữ liệu bị thiếu. Trên thực tế, tài liệu của nó có toàn bộ phần dành riêng để làm việc với dữ liệu bị thiếu .

Gấu trúc thường đại diện cho dữ liệu bị thiếu bằng giá trị NaN (không phải số) . Trong Python, bạn có thể nhận NaN với 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
21, 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
22hoặc 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
23. Bắt đầu với Pandas 1.0, loại mới thích 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
98, 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
25, 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
26, 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
27, và 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
28sử dụng 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
29như một giá trị bị mất tích.

Dưới đây là ví dụ về Pandas DataFrame bị thiếu giá trị:

>>>

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
7

Biến 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
66tham chiếu đến DataFrame với một cột 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
60và bốn giá trị. Giá trị thứ ba 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
32được coi là bị thiếu theo mặc định.

Tính toán với dữ liệu bị thiếu

Nhiều phương thức Pandas bỏ qua 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
32các giá trị khi thực hiện tính toán trừ khi chúng được hướng dẫn rõ ràng là không :

>>>

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
8

Biến 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
66tham chiếu đến DataFrame với một cột 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
60và bốn giá trị. Giá trị thứ ba 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
32được coi là bị thiếu theo mặc định.

Tính toán với dữ liệu bị thiếu

Nhiều phương thức Pandas bỏ qua >>> df = pd.DataFrame(data=data, index=row_labels) >>> df name city age py-score 101 Xavier Mexico City 41 88.0 102 Ann Toronto 28 79.0 103 Jana Prague 33 81.0 104 Yi Shanghai 34 80.0 105 Robin Manchester 38 68.0 106 Amal Cairo 31 61.0 107 Nori Osaka 37 84.0 32các giá trị khi thực hiện tính toán trừ khi chúng được hướng dẫn rõ ràng là không :

Trong ví dụ đầu tiên, 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
34tính giá trị trung bình mà không tính đến 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
35(giá trị thứ ba). Nó chỉ mất 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
36, 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
37và 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
38và trả trung bình của họ, đó là 2,33.

  • Tuy nhiên, nếu bạn hướng dẫn 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    18không bỏ qua 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    32các giá trị với 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    41, thì nó sẽ xem xét chúng và trả về 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    32nếu có bất kỳ giá trị nào bị thiếu trong số dữ liệu.
  • Làm đầy dữ liệu bị thiếu
  • Pandas có một số tùy chọn để điền hoặc thay thế các giá trị bị thiếu bằng các giá trị khác. Một trong những phương pháp thuận tiện nhất là 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    43. Bạn có thể sử dụng nó để thay thế các giá trị bị thiếu bằng:

Các giá trị được chỉ định

>>>

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
9

Biến 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
66tham chiếu đến DataFrame với một cột 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
60và bốn giá trị. Giá trị thứ ba 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
32được coi là bị thiếu theo mặc định.

Tính toán với dữ liệu bị thiếu

>>>

>>> cities = df['city']
>>> cities
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
0

Biến 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
66tham chiếu đến DataFrame với một cột 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
60và bốn giá trị. Giá trị thứ ba 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
32được coi là bị thiếu theo mặc định.

Tính toán với dữ liệu bị thiếu

  • Nhiều phương thức Pandas bỏ qua 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    32các giá trị khi thực hiện tính toán trừ khi chúng được hướng dẫn rõ ràng là không :
  • Trong ví dụ đầu tiên, 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    34tính giá trị trung bình mà không tính đến 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    35(giá trị thứ ba). Nó chỉ mất 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    36, 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    37và 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    38và trả trung bình của họ, đó là 2,33.

Tuy nhiên, nếu bạn hướng dẫn 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
18không bỏ qua 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
32các giá trị với 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
41, thì nó sẽ xem xét chúng và trả về 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
32nếu có bất kỳ giá trị nào bị thiếu trong số dữ liệu.

Làm đầy dữ liệu bị thiếu

Pandas có một số tùy chọn để điền hoặc thay thế các giá trị bị thiếu bằng các giá trị khác. Một trong những phương pháp thuận tiện nhất là 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
43. Bạn có thể sử dụng nó để thay thế các giá trị bị thiếu bằng:

>>>

>>> cities = df['city']
>>> cities
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
1

Biến 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
66tham chiếu đến DataFrame với một cột 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
60và bốn giá trị. Giá trị thứ ba 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
32được coi là bị thiếu theo mặc định.

Tính toán với dữ liệu bị thiếu

Nhiều phương thức Pandas bỏ qua 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
32các giá trị khi thực hiện tính toán trừ khi chúng được hướng dẫn rõ ràng là không :

  • Trong ví dụ đầu tiên, 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    34tính giá trị trung bình mà không tính đến 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    35(giá trị thứ ba). Nó chỉ mất 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    36, 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    37và 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    38và trả trung bình của họ, đó là 2,33.
  • Tuy nhiên, nếu bạn hướng dẫn 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    18không bỏ qua 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    32các giá trị với 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    41, thì nó sẽ xem xét chúng và trả về 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    32nếu có bất kỳ giá trị nào bị thiếu trong số dữ liệu.
  • Làm đầy dữ liệu bị thiếu
  • Pandas có một số tùy chọn để điền hoặc thay thế các giá trị bị thiếu bằng các giá trị khác. Một trong những phương pháp thuận tiện nhất là 
    >>> df = pd.DataFrame(data=data, index=row_labels)
    >>> df
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    103    Jana       Prague   33      81.0
    104      Yi     Shanghai   34      80.0
    105   Robin   Manchester   38      68.0
    106    Amal        Cairo   31      61.0
    107    Nori        Osaka   37      84.0
    
    43. Bạn có thể sử dụng nó để thay thế các giá trị bị thiếu bằng:

Các giá trị được chỉ định

>>>

>>> cities = df['city']
>>> cities
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
2

Biến 

def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
66tham chiếu đến DataFrame với một cột 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
60và bốn giá trị. Giá trị thứ ba 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
32được coi là bị thiếu theo mặc định.

Tính toán với dữ liệu bị thiếu

>>>

>>> cities = df['city']
>>> cities
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
3

Đó là cách bạn sử dụng 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
71.

Tương tự, 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
72lặp qua các hàng và trong mỗi lần lặp lại tạo ra một bộ được đặt tên với (tùy chọn) chỉ mục và dữ liệu:

>>>

>>> cities = df['city']
>>> cities
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
4

Bạn có thể chỉ định tên của tuple đã đặt tên với tham số 

>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
6được đặt thành 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
83theo mặc định. Bạn cũng có thể chỉ định xem có bao gồm các nhãn hàng hay không 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
54, được đặt thành 
def interp_perso(Z_in,var_in,zout): return interpolate.interp1d(Z_in[:],var_in[:],bounds_error=False,fill_value=np.nan)(zout)

Zout =  np.zeros((X.shape[0],X.shape[1]))
for l in range(0,zout.shape[0]):
   Zout[:,:] = zout[l]
   var_out[l] = map(interp_perso,Z_in,var_in,Zout)
94theo mặc định.

Làm việc với chuỗi thời gian

Gấu trúc vượt trội trong việc xử lý chuỗi thời gian . Mặc dù chức năng này một phần dựa trên lịch ngày và thời gian của NumPy , nhưng Pandas cung cấp tính linh hoạt hơn nhiều.

Tạo DataFrames với nhãn chuỗi thời gian

Trong phần này, bạn sẽ tạo Pandas DataFrame bằng cách sử dụng dữ liệu nhiệt độ hàng giờ của một ngày.

Bạn có thể bắt đầu bằng cách tạo một danh sách (hoặc bộ, mảng NumPy hoặc kiểu dữ liệu khác) với các giá trị dữ liệu, sẽ là nhiệt độ hàng giờ được tính bằng độ C :

>>>

>>> cities = df['city']
>>> cities
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
5

Bây giờ bạn có biến 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
86, tham chiếu đến danh sách các giá trị nhiệt độ.

Bước tiếp theo là tạo một chuỗi ngày và giờ. Pandas cung cấp một chức năng rất tiện lợi 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
87, cho mục đích này:

>>>

>>> cities = df['city']
>>> cities
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
6

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
87chấp nhận các đối số mà bạn sử dụng để chỉ định bắt đầu hoặc kết thúc phạm vi, số khoảng thời gian, tần suất, múi giờ và hơn thế nữa.

Bây giờ bạn đã có các giá trị nhiệt độ và ngày giờ tương ứng, bạn có thể tạo DataFrame. Trong nhiều trường hợp, thật tiện lợi khi sử dụng các giá trị ngày-giờ làm nhãn hàng:

>>>

>>> cities = df['city']
>>> cities
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
7

Đó là nó! Bạn đã tạo DataFrame với dữ liệu chuỗi thời gian và chỉ số hàng ngày-giờ.

Lập chỉ mục và cắt lát

Khi bạn đã có Pandas DataFrame với dữ liệu chuỗi thời gian, bạn có thể áp dụng phương pháp cắt để chỉ lấy một phần thông tin một cách thuận tiện:

>>>

>>> cities = df['city']
>>> cities
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
8

Ví dụ này cho thấy cách trích xuất nhiệt độ từ 05:00 đến 14:00 (5 giờ sáng và 2 giờ chiều). Mặc dù bạn đã cung cấp các chuỗi, nhưng Pandas biết rằng các nhãn hàng của bạn là các giá trị ngày-giờ và diễn giải các chuỗi dưới dạng ngày và giờ.

Lấy mẫu lại và cán

Bạn vừa thấy cách kết hợp các nhãn hàng ngày-giờ và sử dụng phương pháp cắt để lấy thông tin bạn cần từ dữ liệu chuỗi thời gian. Điều này chỉ là khởi đầu. Nó trở nên tốt hơn!

Nếu bạn muốn chia một ngày thành bốn khoảng thời gian sáu giờ và nhận được nhiệt độ trung bình cho mỗi khoảng thời gian, thì bạn chỉ cần thực hiện một tuyên bố. Pandas cung cấp phương pháp 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
89mà bạn có thể kết hợp với các phương pháp khác như 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
18:

>>>

>>> cities = df['city']
>>> cities
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
9

Bây giờ bạn có một Pandas DataFrame mới với bốn hàng. Mỗi hàng tương ứng với một khoảng thời gian sáu giờ. Ví dụ: giá trị 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
91là giá trị trung bình của sáu nhiệt độ đầu tiên từ DataFrame 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
92, trong khi giá trị là giá trị trung bình của sáu nhiệt độ 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
93cuối cùng.

Thay vào đó 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
18, bạn có thể áp dụng 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
95hoặc 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
96để lấy nhiệt độ tối thiểu và tối đa cho mỗi khoảng thời gian. Bạn cũng có thể sử dụng 
>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
97để lấy tổng giá trị dữ liệu, mặc dù thông tin này có thể không hữu ích khi bạn đang làm việc với nhiệt độ.

Bạn cũng có thể cần thực hiện một số phân tích cửa sổ luân phiên . Điều này liên quan đến việc tính toán thống kê cho một số hàng liền kề được chỉ định, tạo nên cửa sổ dữ liệu của bạn. Bạn có thể "cuộn" cửa sổ bằng cách chọn một tập hợp các hàng liền kề khác nhau để thực hiện các phép tính của mình.

Cửa sổ đầu tiên của bạn bắt đầu với hàng đầu tiên trong DataFrame của bạn và bao gồm nhiều hàng liền kề như bạn chỉ định. Sau đó, bạn di chuyển cửa sổ của mình xuống một hàng, bỏ hàng đầu tiên và thêm hàng đến ngay sau hàng cuối cùng và tính toán lại cùng một thống kê. Bạn lặp lại quá trình này cho đến khi bạn đến hàng cuối cùng của DataFrame.

Pandas cung cấp phương pháp 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
98cho mục đích này:

>>>

>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
0

Bây giờ bạn có DataFrame với nhiệt độ trung bình được tính toán cho một số cửa sổ ba giờ. Tham số 

>>> df = pd.DataFrame(data=data, index=row_labels)
>>> df
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0
103    Jana       Prague   33      81.0
104      Yi     Shanghai   34      80.0
105   Robin   Manchester   38      68.0
106    Amal        Cairo   31      61.0
107    Nori        Osaka   37      84.0
99chỉ định kích thước của cửa sổ thời gian di chuyển.

Trong ví dụ trên, giá trị thứ ba ( 

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
00) là nhiệt độ trung bình trong ba giờ đầu tiên ( 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
01, 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
02và 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
03). Giá trị thứ tư là nhiệt độ trung bình cho giờ 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
03, 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
05và 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
06. Giá trị cuối cùng là nhiệt độ trung bình trong ba giờ qua, 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
07, 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
08, và 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
09. Hai giá trị đầu tiên bị thiếu vì không có đủ dữ liệu để tính toán chúng.

Lập kế hoạch với dữ liệu gấu trúc

Pandas cho phép bạn trực quan hóa dữ liệu hoặc tạo các lô dựa trên DataFrames . Nó sử dụng Matplotlib ở chế độ nền, vì vậy việc khai thác khả năng âm mưu của Pandas rất giống với làm việc với Matplotlib .

Nếu bạn muốn hiển thị các ô, thì trước tiên bạn cần nhập 

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
10:

>>>

>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
1

Bây giờ bạn có thể sử dụng 

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
11để tạo cốt truyện và 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
12hiển thị nó:

>>>

>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
2

Bây giờ bạn có thể sử dụng 

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
11để tạo cốt truyện và 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
12hiển thị nó:

Hướng dẫn python vertical interpolation - phép nội suy dọc python

Bây giờ 

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
13trả về một 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
14đối tượng trông giống như sau:

Bạn cũng có thể áp dụng 

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
15và nhận được kết quả tương tự. Cả hai 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
13và 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
15có nhiều tham số tùy chọn mà bạn có thể sử dụng để chỉ định giao diện của âm mưu của bạn. Một số trong số chúng được chuyển trực tiếp đến các phương thức Matplotlib cơ bản.

>>>

>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
3

Bây giờ bạn có thể sử dụng 

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
11để tạo cốt truyện và 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
12hiển thị nó:

Bây giờ 

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
13trả về một 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
14đối tượng trông giống như sau:

>>>

>>> df.city
101    Mexico City
102        Toronto
103         Prague
104       Shanghai
105     Manchester
106          Cairo
107          Osaka
Name: city, dtype: object
4

Bây giờ bạn có thể sử dụng 

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
11để tạo cốt truyện và 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
12hiển thị nó:

Hướng dẫn python vertical interpolation - phép nội suy dọc python

Bây giờ 

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
13trả về một 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
14đối tượng trông giống như sau:

Bạn cũng có thể áp dụng >>> df.head(n=2) name city age py-score 101 Xavier Mexico City 41 88.0 102 Ann Toronto 28 79.0 >>> df.tail(n=2) name city age py-score 106 Amal Cairo 31 61.0 107 Nori Osaka 37 84.0 15và nhận được kết quả tương tự. Cả hai >>> df.head(n=2) name city age py-score 101 Xavier Mexico City 41 88.0 102 Ann Toronto 28 79.0 >>> df.tail(n=2) name city age py-score 106 Amal Cairo 31 61.0 107 Nori Osaka 37 84.0 13và >>> df.head(n=2) name city age py-score 101 Xavier Mexico City 41 88.0 102 Ann Toronto 28 79.0 >>> df.tail(n=2) name city age py-score 106 Amal Cairo 31 61.0 107 Nori Osaka 37 84.0 15có nhiều tham số tùy chọn mà bạn có thể sử dụng để chỉ định giao diện của âm mưu của bạn. Một số trong số chúng được chuyển trực tiếp đến các phương thức Matplotlib cơ bản.

Bạn có thể lưu hình của mình bằng cách xâu chuỗi các phương pháp 

>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
18và 
>>> df.head(n=2)
       name         city  age  py-score
101  Xavier  Mexico City   41      88.0
102     Ann      Toronto   28      79.0

>>> df.tail(n=2)
     name   city  age  py-score
106  Amal  Cairo   31      61.0
107  Nori  Osaka   37      84.0
19:

  • Câu lệnh này tạo cốt truyện và lưu nó dưới dạng tệp được gọi 
    >>> df.head(n=2)
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    
    >>> df.tail(n=2)
         name   city  age  py-score
    106  Amal  Cairo   31      61.0
    107  Nori  Osaka   37      84.0
    
    20trong thư mục làm việc của bạn.
  • Bạn có thể lấy các loại ô khác bằng Pandas DataFrame. Ví dụ: bạn có thể hình dung dữ liệu ứng viên công việc của mình từ trước đó dưới dạng biểu đồ với 
    >>> df.head(n=2)
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    
    >>> df.tail(n=2)
         name   city  age  py-score
    106  Amal  Cairo   31      61.0
    107  Nori  Osaka   37      84.0
    
    21:
  • Trong ví dụ này, bạn trích xuất dữ liệu điểm và tổng điểm của bài kiểm tra Python và trực quan hóa nó bằng biểu đồ. Cốt truyện kết quả trông như thế này:
  • Đây chỉ là cái nhìn cơ bản. Bạn có thể điều chỉnh chi tiết với các thông số tùy chọn bao gồm 
    >>> df.head(n=2)
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    
    >>> df.tail(n=2)
         name   city  age  py-score
    106  Amal  Cairo   31      61.0
    107  Nori  Osaka   37      84.0
    
    21, Matplotlib's
    >>> df.head(n=2)
           name         city  age  py-score
    101  Xavier  Mexico City   41      88.0
    102     Ann      Toronto   28      79.0
    
    >>> df.tail(n=2)
         name   city  age  py-score
    106  Amal  Cairo   31      61.0
    107  Nori  Osaka   37      84.0
    
    23 , và nhiều thông số khác. Bạn có thể tìm thấy những lời giải thích chi tiết trong Anatomy of Matplotlib .

Đọc thêm

  • Pandas DataFrames là các đối tượng rất toàn diện hỗ trợ nhiều thao tác không được đề cập trong hướng dẫn này. Một số trong số này bao gồm:
  • Lập chỉ mục phân cấp (nhiều cấp)
  • Phân nhóm
  • Hợp nhất, nối và nối
  • Làm việc với dữ liệu phân loại
  • Các quan chức Pandas hướng dẫn tóm tắt một số các tùy chọn có sẵn độc đáo. Nếu bạn muốn tìm hiểu thêm về Pandas và DataFrames , thì bạn có thể xem các hướng dẫn sau:
  • Làm sạch dữ liệu Pythonic với gấu trúc và NumPy
  • Pandas DataFrames 101
  • Giới thiệu về Gấu trúc và Vincent
  • Gấu trúc Python: Thủ thuật & Tính năng có thể bạn chưa biết
  • Gấu trúc thành ngữ: Thủ thuật & tính năng có thể bạn chưa biết

Đọc CSV với gấu trúc

Viết CSV với gấu trúc

Đọc và ghi tệp CSV bằng Python

Đọc và ghi tệp CSV

Sử dụng gấu trúc để đọc tệp Excel lớn bằng Python

  • Nhanh chóng, linh hoạt, dễ dàng và trực quan: Cách tăng tốc dự án gấu trúc của bạn
  • Bạn đã biết rằng Pandas DataFrames xử lý dữ liệu hai chiều. Nếu bạn cần làm việc với dữ liệu được gắn nhãn trong nhiều hơn hai chiều, bạn có thể xem xarray , một thư viện Python mạnh mẽ khác dành cho khoa học dữ liệu với các tính năng rất giống với Pandas.
  • Nếu bạn làm việc với dữ liệu lớn và muốn có trải nghiệm giống như DataFrame, thì bạn có thể cho Dask một cơ hội và sử dụng API DataFrame của nó . Một Dask DataFrame chứa nhiều Pandas DataFrame và thực hiện tính toán một cách lười biếng .
  • Phần kết luận
  • Bây giờ bạn đã biết Pandas DataFrame là gì, một số tính năng của nó và cách bạn có thể sử dụng nó để làm việc với dữ liệu một cách hiệu quả. Pandas DataFrames là cấu trúc dữ liệu mạnh mẽ, thân thiện với người dùng mà bạn có thể sử dụng để hiểu sâu hơn về tập dữ liệu của mình!
  • Trong hướng dẫn này, bạn đã học được:

Pandas DataFrame là gì và cách tạo một Pandas DataFrame

Cách truy cập, sửa đổi, thêm, sắp xếp, lọc và xóa dữ liệu

Hướng dẫn python vertical interpolation - phép nội suy dọc python

Cách sử dụng quy trình NumPy với DataFrames
Cách xử lý các giá trị bị thiếu
Cách làm việc với dữ liệu chuỗi thời gian Prev: Python: Tôi có thể làm gì với Python?
Cách trực quan hóa dữ liệu có trong DataFrames Next: Python: Cách in có định dạng trong Python với bài toán in các thừa số nguyên tố

Bạn đã học đủ để bao quát các nguyên tắc cơ bản của DataFrames. Nếu bạn muốn tìm hiểu sâu hơn về cách làm việc với dữ liệu bằng Python , hãy xem toàn bộ các hướng dẫn về Gấu trúc .