I have a dataframe and I want to remove rows containing non-numeric values and also convert float to int
# Dataframe
productid
7819210
9600146.0
031351AA2
3255214
0018392MM
1785506
6924986
1915444
6007828.0
# cuurent approach
df.productid = df[df.productid.apply(lambda x: str(x).isnumeric())].astype(int) # It also remove floating point values because they contain decimal which is non-numeric
I also made a method which does this
def filternumeric(x):
if (re.search('\d+', str(x))): pass
else: return x
df.productid = df[df.productid.apply(filternumeric)].astype(int)
But it is also not working correctly. Any better suggestions ?