import pandas as pd
import numpy as np
n = np.arange(20, dtype=float).reshape(5,4)
n[2,3] = np.nan
index = ['index1', 'index2', 'index3', 'index4', 'index5']
columns = ['column1', 'column2', 'column3', 'column4']
frame3 = pd.DataFrame(data=n, index=index, columns=columns)
frame3
| column1 | column2 | column3 | column4 |
---|
index1 | 0.0 | 1.0 | 2.0 | 3.0 |
---|
index2 | 4.0 | 5.0 | 6.0 | 7.0 |
---|
index3 | 8.0 | 9.0 | 10.0 | NaN |
---|
index4 | 12.0 | 13.0 | 14.0 | 15.0 |
---|
index5 | 16.0 | 17.0 | 18.0 | 19.0 |
---|
frame3.isnull()
| column1 | column2 | column3 | column4 |
---|
index1 | False | False | False | False |
---|
index2 | False | False | False | False |
---|
index3 | False | False | False | True |
---|
index4 | False | False | False | False |
---|
index5 | False | False | False | False |
---|
frame3.isnull().any()
column1 False
column2 False
column3 False
column4 True
dtype: bool
判断有空值的行
frame3.isnull().any(axis = 1)
index1 False
index2 False
index3 True
index4 False
index5 False
dtype: bool
frame3.isnull().T.any()
index1 False
index2 False
index3 True
index4 False
index5 False
dtype: bool
应用:取非空值的行
frame3[frame3.isnull().any(axis = 1)==False]
| column1 | column2 | column3 | column4 |
---|
index1 | 0.0 | 1.0 | 2.0 | 3.0 |
---|
index2 | 4.0 | 5.0 | 6.0 | 7.0 |
---|
index4 | 12.0 | 13.0 | 14.0 | 15.0 |
---|
index5 | 16.0 | 17.0 | 18.0 | 19.0 |
---|
应用:取有空值的行
frame3[frame3.isnull().any(axis = 1)==True]
| column1 | column2 | column3 | column4 |
---|
index3 | 8.0 | 9.0 | 10.0 | NaN |
---|