不使用groupby我如何过滤数据没有NaN?
假设我有一个矩阵,其中客户将填写“N/ a”,“N/ a”或其任何变体,而其他人则留空:
import pandas as pd
import numpy as np
df = pd.DataFrame({'movie': ['thg', 'thg', 'mol', 'mol', 'lob', 'lob'],
'rating': [3., 4., 5., np.nan, np.nan, np.nan],
'name': ['John', np.nan, 'N/A', 'Graham', np.nan, np.nan]})
nbs = df['name'].str.extract('^(N/A|NA|na|n/a)')
nms=df[(df['name'] != nbs) ]
输出:
>>> nms
movie name rating
0 thg John 3
1 thg NaN 4
3 mol Graham NaN
4 lob NaN NaN
5 lob NaN NaN
我如何过滤NaN值,这样我就可以得到这样的结果:
movie name rating
0 thg John 3
3 mol Graham NaN
我猜我需要像~np这样的东西。Isnan,但tilda不适用于字符串。