Pandas extract non-empty row values

When doing data processing, we will encounter rows in which the value of a certain column is not empty in the table to be extracted. We can easily handle it through pandas. The specific steps are as follows:

1. Create a form 

import numpy as np
import pandas as pd
from pandas import Series,DataFrame
data=DataFrame()
data['a']=[1,2,3,4]
data['b']=[1,2,np.nan,np.nan]

2. Form properties

a b
0 1 1.0
1 2 2.0
2 3 NaN
3 4 NaN

3. Get Boolean value

data['b'].notnull()
0     True
1     True
2    False
3    False
Name: b, dtype: bool 

4. Get rows with non-null values

data[data['b'].notnull()]
a b
0 1 1.0
1 2 2.0

 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_43734080/article/details/127823543