Skip to content
Advertisement

Find rows that have in the cells duplicates symbols

I have a dataframe that has columns with strings and columns with floats.

some values in the cells have two symbols like this:

-0.015-0.156 ==> middle ‘-‘ is not ok, two dots not ok

0.014-0.106 ==> middle ‘-‘ is not ok, two dots not ok

0.013.0.156 ==> two dots not ok

-0.015 ==> ok

0.013 ==> ok

I want to find all the rows that have a value that is “not ok”.

how can I do it?, Maybe with a condition of two dots.

Advertisement

Answer

try using, pd.to_numeric by setting error to coerce

import pandas as pd

df = pd.DataFrame(
    {"col":["-0.015-0.156", "0.014-0.106", "0.013.0.156", "-0.015", "0.013"]}
)

df.loc[pd.to_numeric(df['col'], errors='coerce').isna(), :]

            col
0  -0.015-0.156
1   0.014-0.106
2   0.013.0.156
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement