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
JavaScript
x
8
1
import pandas as pd
2
3
df = pd.DataFrame(
4
{"col":["-0.015-0.156", "0.014-0.106", "0.013.0.156", "-0.015", "0.013"]}
5
)
6
7
df.loc[pd.to_numeric(df['col'], errors='coerce').isna(), :]
8
JavaScript
1
5
1
col
2
0 -0.015-0.156
3
1 0.014-0.106
4
2 0.013.0.156
5