I checked this post: finding non-numeric rows in dataframe in pandas? but it doesn't really answer my question.
my sample data:
import pandas as pd
d = {
'unit': ['UD', 'UD', 'UD', 'UD', 'UD','UD'],
'N-D': [ 'Q1', 'Q2', 'Q3', 'Q4','Q5','Q6'],
'num' : [ -1.48, 1.7, -6.18, 0.25, 'sum(d)', 0.25]
}
df = pd.DataFrame(d)
it looks like this:
N-D num unit
0 Q1 -1.48 UD
1 Q2 1.70 UD
2 Q3 -6.18 UD
3 Q4 0.25 UD
4 Q5 sum(d) UD
5 Q6 0.25 UD
I want to filter out only the rows in column 'num' that are NON-NUMERIC. I want all of the columns for only the rows that contain non-numeric values for column 'num'.
desired output:
N-D num unit
4 Q5 sum(d) UD
my attempts:
nonnumeric=df[~df.applymap(np.isreal).all(1)] #didn't work, it pulled out everything, besides i want the condition to check only column 'num'.
nonnumeric=df['num'][~df.applymap(np.isreal).all(1)] #didn't work, it pulled out all the rows for column 'num' only.