使用dropna
带有参数subset
的指定检查列NaN
S:
data = data.dropna(subset=['sms'])
print (data)
id city department sms category
1 2 lhr revenue good 1
用另一种解决方案boolean indexing
和notnull
:
data = data[data['sms'].notnull()]
print (data)
id city department sms category
1 2 lhr revenue good 1
另一种选择query
:
print (data.query("sms == sms"))
id city department sms category
1 2 lhr revenue good 1
#[300000 rows x 5 columns]
data = pd.concat([data]*100000).reset_index(drop=True)
In [123]: %timeit (data.dropna(subset=['sms']))
100 loops, best of 3: 19.5 ms per loop
In [124]: %timeit (data[data['sms'].notnull()])
100 loops, best of 3: 13.8 ms per loop
In [125]: %timeit (data.query("sms == sms"))
10 loops, best of 3: 23.6 ms per loop