The exact logic is unclear as your description and example are not exactly matching, but for the general logic, assuming you want to flag values that are ending with 2 digits or not between -100-200, you can use pandas.to_numerid
+between
and a regex with str.extract
+str.len
:
import numpy as np
# is the numeric value between -100 and 200?
m1 = pd.to_numeric(df['name2'], errors='coerce').between(-100, 200)
# is the count of the decimal not 2?
m2 = df['name2'].str.extract(r'\.(\d*[1-9]+)', expand=False).str.len().ne(2)
df['Error'] = np.where(m1&m2, 'No Issue', 'Issue')
Output:
Name name2 Error
0 A 0.029 No Issue
1 B 0 No Issue
2 V 2 No Issue
3 D -0.000029 No Issue
4 E -0.11 Issue
Reproducible input:
df = pd.DataFrame({'Name': list('ABVDE'),
'name2': ['0.029', '0', '2', '-0.000029', '-0.11']
})
Intermediates:
Name name2 m1 m2 m1&m2 Error
0 A 0.029 True True True No Issue
1 B 0 True True True No Issue
2 V 2 True True True No Issue
3 D -0.000029 True True True No Issue
4 E -0.11 True False False Issue