I have a column in my data that contains these kind of values
2
2
yes
2
yes
In python pandas how would I identify the entire row
Here's a way to solve this. I've included code to build the DataFrame,
find the string values and then drop them. df.drop returns a modified copy
of the original df unless you specify inplace=True, so if you want, you can assign the original name of the df df = df.drop...
, or use the inplace argument.
import pandas as pd
import numpy as np
# build the df
df = pd.DataFrame({'col_name' : [2, 2, 'yes', 2, 'yes']})
print(df)
col_name
0 2
1 2
2 yes
3 2
4 yes
# ask what are the types in column
df.col_name.apply(type)
0 <class 'int'>
1 <class 'int'>
2 <class 'str'>
3 <class 'int'>
4 <class 'str'>
Name: col_name, dtype: object
# you can see that the strings are in row 2 and 4
# and drop them like this
df.drop([2, 4], axis='rows')
col_name
0 2
1 2
3 2
IIUC:
df = df[~pd.to_numeric(df['col'], errors='coerce').isna()]
or
df = df[pd.to_numeric(df['col'], errors='coerce').notna()]