Without using groupby how would I filter data without NaN ?
Suppose I have a matrix in which clients will fill in 'N / A', 'N / A' or any of its variants, while others leave this field empty:
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) ]
exit:
>>> nms movie name rating 0 thg John 3 1 thg NaN 4 3 mol Graham NaN 4 lob NaN NaN 5 lob NaN NaN
How would I filter NaN values โโto get the results to work as follows:
movie name rating 0 thg John 3 3 mol Graham NaN
I assume I need something like ~np.isnan but the tilde does not work with strings.
python pandas dataframe
ccsv Mar 21 '14 at 6:04 2014-03-21 06:04
source share