Pandas uses str.contains to filter error [How to Solve]

When using pandas to filter excel,


The following error messages appear:

ValueError: Cannot mask with non-boolean array containing NA/NaN values

It is reported that the grouping column contains non-string contents. Because the use of .Str.contains requires that the field must be a string and cannot have numbers,
so it is added to the code

df.loc[df['threat_type'].str.contains("DGA", na=False)]

This enables the function to directly ignore non-string situations.

Read More: