. Advertisement .
..3..
. Advertisement .
..4..
I encountered the following problem in completing my work:
ValueError: cannot index with vector containing NA / NaN values
Below is the code I ran:
DF[DF.col.str.contains("foo")]
DF[DF.col.notnull()][DF.col.dropna().str.contains("foo")]
What’s causing it, and how can it be resolved in the “Cannot mask with non-boolean array containing NA / NaN values“ in the python?
The cause:
I have a flag for that:
From the above program, you can see that the data in your program are not strings, they are NA or NaN. However str.contains has a requirement that it must be a string, cannot numbers or mix with numbers. This is the reason of your error.
Solution:
To fix this error, let’s do as my following suggestion:
Another way for this error is:
Or
You can use the following for columns that do not contain a single word:
We hope you find this helpful.