1

I read in a csv like this

df = pd.read_csv(self.file_path, dtype=str)

then I try this:

 df = df[df["MY_COLUMN"].apply(lambda x: x.isnumeric())]

I get an AttributeError:

AttributeError: 'float' object has no attribute 'isnumeric'

Why is this happening? The column contains mostly digits.

I want to filter out the ones where there are no digits.

This question is not how to achieve that or do it better but why do I get an AttributeError here?

1 Answer 1

1

Why is this happening?

I think because NaN is not converting to string if use dtype=str, still is missing value, so type=float

Use Series.str.isnumeric for working isnumeric with missing values like all text functions in pandas:

df[df["MY_COLUMN"].str.isnumeric()]
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the answer but i explicitly am not asking how to do it better or get it working but why i get an error even with stating the dtypes when reading it in.
@goodsnek - I think because NaN is not converting to string if use dtype=str

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.