Làm cách nào để kiểm tra xem một cột có giá trị trống trong gấu trúc không?

Hôm nay chúng ta sẽ tìm hiểu cách nhanh chóng tìm xem một hoặc nhiều ô trong các hàng hoặc cột DataFrame của gấu trúc có chứa các giá trị trống hay không [Null, N/A, nan, Không]

Tạo một DataFrame giả

Trước hết, chúng tôi sẽ tạo một Tập dữ liệu rất đơn giản mà bạn có thể sử dụng để làm theo ví dụ này

import pandas as pd
import numpy as np

prog_language = [np.nan, 'Javascript', 'Python', 'Java', 'Python', 'Java']
office = ['Bangkok', 'Osaka', 'Paris', None, pd.NA, 'Paris']
salary = [133.0, 136.0, 127.0, 185.0, 164.0, pd.NA]
data = dict[office=office, prog_language = prog_language, salary = salary]
test_df = pd.DataFrame[data=data]
test_df.head[]

Đây là dữ liệu thử nghiệm của chúng tôi. Lưu ý rằng một số ô trong DataFrame chứa null/NAN/không có giá trị trống

officeprog_languagesalary0BangkokNaN133.01OsakaJavascript136.02ParisPython127.03NoneJava185.04Python164.0

Kiểm tra xem một ô DataFrame cụ thể có trống không

Chúng ta có thể sử dụng hàm gấu trúc isna hoặc isnull và bộ truy cập loc hoặc iloc để xác định xem một ô cụ thể có trống không

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]

Điều này sẽ trả lại như sau

Your cell is empty.

Theo cách tương tự, sử dụng isnull và bộ bổ sung bộ chỉ mục loc [iloc] để kiểm tra xem ô của chúng ta có chứa giá trị null hay không

if pd.isnull[test_df.iloc[2,1]] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]

Kiểm tra xem các ô có trống trong một cột không

Giả sử chúng ta muốn kiểm tra xem một cột có chứa các ô trống không

# define a column to search
my_col = test_df['prog_language']
my_col.isna[].any[]

Điều này trả về Đúng

Tìm nếu các giá trị nan tồn tại trong DataFrame

Để kiểm tra toàn bộ DataFrame, chúng tôi sử dụng một kỹ thuật tương tự

test_df.isna[].any[]

Điều này trả về một Sê-ri boolean, mỗi giá trị liên quan đến từng cột DataFrame của chúng tôi

office           True
prog_language    True
salary           True
dtype: bool

Ghi chú. kỹ thuật này áp dụng cho việc chúng tôi muốn kiểm tra các giá trị NAN trong nhiều cột hoặc hàng

subset = test_df[['office', 'salary']]

# find rows with nulls
subset.isna[].any[axis=1]

# find columns with nulls
subset.isna[].any[]

Tìm kiếm các hàng DataFrame chứa các giá trị nan

Nếu chúng tôi muốn tìm các hàng trong DataFrame chứa bất kỳ giá trị trống nào, chúng tôi có thể sử dụng đoạn mã sau

Gấu trúc coi Không và NaN về cơ bản có thể hoán đổi cho nhau để chỉ ra các giá trị bị thiếu hoặc null. Để tạo thuận lợi cho quy ước này, có một số chức năng hữu ích để phát hiện, xóa và thay thế các giá trị null trong Pandas DataFrame

  • isnull[]
  • có giá trị[]
  • dropna[]
  • điền []
  • thay thế[]
  • nội suy[]

Trong bài viết này, chúng tôi đang sử dụng tệp CSV, để tải xuống tệp CSV đã sử dụng, hãy nhấp vào đây

Kiểm tra các giá trị bị thiếu bằng isnull[] và notnull[]

Để kiểm tra các giá trị còn thiếu trong Pandas DataFrame, chúng tôi sử dụng hàm isnull[] và notnull[]. Cả hai chức năng đều giúp kiểm tra xem một giá trị có phải là NaN hay không. Các chức năng này cũng có thể được sử dụng trong Pandas Series để tìm các giá trị null trong một chuỗi

Kiểm tra các giá trị bị thiếu bằng cách sử dụng isnull[]

Để kiểm tra các giá trị null trong Pandas DataFrame, chúng tôi sử dụng hàm isnull[] hàm này trả về khung dữ liệu của các giá trị Boolean là True cho các giá trị NaN. Mã số 1.  

con trăn




________số 8

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
1

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
3

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
4

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 # importing pandas as pd0# importing pandas as pd1# importing pandas as pd2# importing pandas as pd3# importing pandas as pd4# importing pandas as pd5# importing pandas as pd6# importing pandas as pd7# importing pandas as pd8

# importing pandas as pd9import0import1import2# importing pandas as pd4import4# importing pandas as pd4import6import7

# importing pandas as pd9import9

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
00
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
01# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
03# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
05
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
06

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
07

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
08
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
10
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
12

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
13

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
14

Đầu ra.

  Mã #2.

con trăn




if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
15

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
18

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
19

import0

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 import2

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
18

import4

import5

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 import7

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
18

import9

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
30

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
31

Đầu ra. Như thể hiện trong hình ảnh đầu ra, chỉ những hàng có Giới tính = NULL được hiển thị.

 

Kiểm tra các giá trị bị thiếu bằng cách sử dụng notnull[]

Để kiểm tra các giá trị null trong Pandas Dataframe, chúng tôi sử dụng hàm notnull[] hàm này trả về khung dữ liệu của các giá trị Boolean là Sai đối với các giá trị NaN. Mã số 3.  

con trăn




________số 8

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
1

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
3

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
4

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 # importing pandas as pd0# importing pandas as pd1# importing pandas as pd2# importing pandas as pd3# importing pandas as pd4# importing pandas as pd5# importing pandas as pd6# importing pandas as pd7# importing pandas as pd8

# importing pandas as pd9import0import1import2# importing pandas as pd4import4# importing pandas as pd4import6import7

# importing pandas as pd9import9

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
00
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
01# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
03# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
05
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
06

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
68

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
08
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
10
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
12

 

# importing pandas as pd04

# importing pandas as pd05

Đầu ra.

  Mã #4.

con trăn




if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
15

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
18

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
19

import0

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 import2

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
18

import4

import5

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 # importing pandas as pd18

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
18

import9

# importing pandas as pd21

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
31

Đầu ra. Như thể hiện trong hình ảnh đầu ra, chỉ những hàng có Giới tính = KHÔNG NULL được hiển thị.

 

Điền các giá trị còn thiếu bằng cách sử dụng fillna[], thay thế[] và nội suy[]

Để điền các giá trị null vào bộ dữ liệu, chúng tôi sử dụng hàm fillna[], replace[] và interpolate[], các hàm này thay thế các giá trị NaN bằng một số giá trị của riêng chúng. Tất cả các chức năng này giúp điền vào các giá trị null trong bộ dữ liệu của DataFrame. Hàm nội suy [] về cơ bản được sử dụng để điền các giá trị NA trong khung dữ liệu nhưng nó sử dụng nhiều kỹ thuật nội suy khác nhau để điền các giá trị bị thiếu thay vì mã hóa cứng giá trị. Mã số 1. Điền giá trị null với một giá trị duy nhất

con trăn




________số 8

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
1

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
3

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
4

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 # importing pandas as pd0# importing pandas as pd1# importing pandas as pd2# importing pandas as pd3# importing pandas as pd4# importing pandas as pd5# importing pandas as pd6# importing pandas as pd7# importing pandas as pd8

# importing pandas as pd9import0import1import2# importing pandas as pd4import4# importing pandas as pd4import6import7

# importing pandas as pd9import9

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
00
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
01# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
03# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
05
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
06

 

# importing pandas as pd59

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
08
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
10
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
12

 

# importing pandas as pd65

# importing pandas as pd66# importing pandas as pd67

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
12

Đầu ra.

  Mã #2. Điền các giá trị null bằng các giá trị trước đó 

con trăn




________số 8

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
1

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
3

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
4

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 # importing pandas as pd0# importing pandas as pd1# importing pandas as pd2# importing pandas as pd3# importing pandas as pd4# importing pandas as pd5# importing pandas as pd6# importing pandas as pd7# importing pandas as pd8

# importing pandas as pd9import0import1import2# importing pandas as pd4import4# importing pandas as pd4import6import7

# importing pandas as pd9import9

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
00
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
01# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
03# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
05
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
06

 

# importing pandas as pd59

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
08
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
10
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
12

 

import11

import12

_______913____16____915____112

Đầu ra.

  Mã #3. Điền giá trị null với giá trị tiếp theo 

con trăn




________số 8

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
1

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
3

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
4

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 # importing pandas as pd0# importing pandas as pd1# importing pandas as pd2# importing pandas as pd3# importing pandas as pd4# importing pandas as pd5# importing pandas as pd6# importing pandas as pd7# importing pandas as pd8

# importing pandas as pd9import0import1import2# importing pandas as pd4import4# importing pandas as pd4import6import7

# importing pandas as pd9import9

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
00
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
01# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
03# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
05
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
06

 

# importing pandas as pd59

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
08
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
10
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
12

 

import59

import13

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6______962
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
12

Đầu ra.

  Mã #4. Điền các giá trị null vào Tệp CSV 

con trăn




if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
15

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
18

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
19

import0

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 import2

 

import72

import73

import74import75____976import77import78

Bây giờ chúng ta sẽ điền vào tất cả các giá trị null trong cột Giới tính bằng “Không có giới tính”

con trăn




if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
15

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
18

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
19

import0

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 import2

 

import87

import88

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 import90
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
12

 

import0

Đầu ra.

Mã số 5. Điền giá trị null bằng phương thức replace[] 

con trăn




if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
15

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
18

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
19

import0

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 import2

 

import72

import73

import74import75____976import77import78

Đầu ra.

Bây giờ chúng ta sẽ thay thế tất cả giá trị Nan trong khung dữ liệu bằng giá trị -99.

con trăn




if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
15

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
18

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
19

import0

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 import2

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
18

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
017

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
018
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
020
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
022
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
023
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
12

Đầu ra.

  Mã #6. Sử dụng hàm interpolate[] để điền vào các giá trị còn thiếu bằng phương pháp tuyến tính.

con trăn




________số 8

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
18

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
029

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
08
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
032
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
033# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
035# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
037# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
039# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
041# importing pandas as pd8

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
043
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
044
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
039# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
047# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
049# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
051# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
039# importing pandas as pd8

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
043
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
056
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
057# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
059# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
039# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
051# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
065# importing pandas as pd8

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
043
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
068
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
069# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
051# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
039# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
039# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
077
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
078

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
18

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
080

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
08

Hãy nội suy các giá trị còn thiếu bằng phương pháp Tuyến tính. Lưu ý rằng phương pháp Tuyến tính bỏ qua chỉ mục và coi các giá trị cách đều nhau.  

con trăn




if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
082

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
083
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6______1085
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
086
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
088
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
12

Đầu ra.

Như chúng ta có thể thấy đầu ra, các giá trị trong hàng đầu tiên không thể được điền vì hướng điền các giá trị là về phía trước và không có giá trị nào trước đó có thể được sử dụng trong phép nội suy.

Loại bỏ các giá trị bị thiếu bằng cách sử dụng dropna[]

Để loại bỏ các giá trị null khỏi khung dữ liệu, chúng tôi đã sử dụng hàm dropna[] hàm này loại bỏ các Hàng/Cột của bộ dữ liệu có giá trị Null theo các cách khác nhau. Mã số 1. Xoá hàng có ít nhất 1 giá trị null.  

con trăn




________số 8

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
1

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
3

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
4

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 # importing pandas as pd0# importing pandas as pd1# importing pandas as pd2# importing pandas as pd3# importing pandas as pd4# importing pandas as pd5# importing pandas as pd6# importing pandas as pd7# importing pandas as pd8

# importing pandas as pd9import0import1import2# importing pandas as pd6import4# importing pandas as pd4import6# importing pandas as pd8

# importing pandas as pd9import9# importing pandas as pd2

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
120# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
01# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
03# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
05# importing pandas as pd8

# importing pandas as pd9

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
129____1130
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
131
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
06

 

# importing pandas as pd59

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
08
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
10
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
12

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
18

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
08

Bây giờ chúng tôi loại bỏ các hàng có ít nhất một giá trị Nan [giá trị Null]

con trăn




________số 8

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
1

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
3

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
4

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 # importing pandas as pd0# importing pandas as pd1# importing pandas as pd2# importing pandas as pd3# importing pandas as pd4# importing pandas as pd5# importing pandas as pd6# importing pandas as pd7# importing pandas as pd8

# importing pandas as pd9import0import1import2# importing pandas as pd6import4# importing pandas as pd4import6# importing pandas as pd8

# importing pandas as pd9import9# importing pandas as pd2

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
120# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
01# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
03# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
05# importing pandas as pd8

# importing pandas as pd9

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
129____1130
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
131
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
06

 

# importing pandas as pd59

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
08
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
10
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
12

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
190

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
191

Đầu ra.

Mã số 2. Xoá hàng nếu thiếu tất cả các giá trị trong hàng đó.

con trăn




________số 8

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
1

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
3

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
4

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 # importing pandas as pd0# importing pandas as pd1# importing pandas as pd2# importing pandas as pd3import05# importing pandas as pd7# importing pandas as pd8

# importing pandas as pd9import0import1import2# importing pandas as pd6import4# importing pandas as pd4import6# importing pandas as pd8

# importing pandas as pd9import9# importing pandas as pd2

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
120# importing pandas as pd6
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
03# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
05# importing pandas as pd8

# importing pandas as pd9

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
129____1130
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
131
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
06

 

# importing pandas as pd59

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
08
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
10
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
12

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
18

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
08

Bây giờ chúng tôi thả một hàng có tất cả dữ liệu bị thiếu hoặc chứa giá trị null [NaN]

con trăn




________số 8

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
1

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
3

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
4

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 # importing pandas as pd0# importing pandas as pd1# importing pandas as pd2# importing pandas as pd3import05# importing pandas as pd7# importing pandas as pd8

# importing pandas as pd9import0import1import2# importing pandas as pd6import4# importing pandas as pd4import6# importing pandas as pd8

# importing pandas as pd9import9# importing pandas as pd2

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
120# importing pandas as pd6
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
03# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
05# importing pandas as pd8

# importing pandas as pd9

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
129____1130
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
131
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
06

 

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
08
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
10
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
12

 

import83

import84

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 import86
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
12

Đầu ra.

Mã số 3. Bỏ các cột có ít nhất 1 giá trị null.

con trăn




________số 8

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
0

import91

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
1

import

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
3

import91

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
4

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
5
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
6 # importing pandas as pd0# importing pandas as pd1# importing pandas as pd2# importing pandas as pd3import05# importing pandas as pd7# importing pandas as pd8

# importing pandas as pd9import0import1import2# importing pandas as pd6import4# importing pandas as pd4import6# importing pandas as pd8

# importing pandas as pd9import9# importing pandas as pd2

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
120# importing pandas as pd6
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
03# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
05# importing pandas as pd8

# importing pandas as pd9

if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
129_______82
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
327# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
329# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
331# importing pandas as pd4
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
131
if pd.isna[test_df.loc[2,'office']] is False:
    print["Your cell is empty."]
else:
    print["Your cell is not empty."]
06

Làm cách nào để kiểm tra giá trị null trong cột trong gấu trúc?

Các phương thức pandas isnull[] và notnull[] được sử dụng để kiểm tra và quản lý các giá trị NULL trong khung dữ liệu.

Làm cách nào để tìm các ô trống trong DataFrame của gấu trúc?

Kiểm tra xem một ô DataFrame cụ thể có trống không . pd. isna[test_df. loc[2,'office']] là Sai. print["Ô của bạn trống. "] khác. print["Ô của bạn không trống. "]

Chủ Đề