Hey
I have this excel code i try to translate into python. I am getting some wrong answers and i need help to figure it out..
I have a dataset where I try ti check if a value is bigger or lower than two other values.
When i Run the code it gets the logic wrong and i do not know why? Marked in yellow what returns wrong answer...
![[Image: MIcSh.jpg]](https://i.stack.imgur.com/MIcSh.jpg)
Can anyone help to find out what I am doing wrong?
I have this excel code i try to translate into python. I am getting some wrong answers and i need help to figure it out..
I have a dataset where I try ti check if a value is bigger or lower than two other values.
#Dataset
Date STD-3 STD-25 STD-2 STD-15 STD-1 Data STD1 STD15 STD2 STD25 STD3
11.05.2022 -0,057406797 -0,047838998 -0,038271198 -0,028703399 -0,019135599 0,021233631 0,019135599 0,028703399 0,038271198 0,047838998 0,057406797
#Excel Code:
"Data" < "STD1" and "Data" > "STD-1" = 0
"Data" > "STD1" and "Data" < "STD15" = 1
"Data" > "STD15" and "Data" < "STD2" = 1,5
"Data" > "STD2" and "Data" < "STD25" = 2
"Data" > "STD25" and "Data" < "STD3" = 2,5
"Data" > "STD3" = 3
"Data" < "STD-1" and "Data" > "STD-15" = -1
"Data" < "STD-15" and "Data" > "STD-2" = -1,5
"Data" < "STD-2" and "Data" > "STD-25" = -2
"Data" < "STD-25" and "Data" > "STD-3" = -2,5
"Data" > "STD3" = -3
#Python Code:
condition = [((df['Data'] < df['STD1']) & (df['Data'] > df['STD-1'])),
((df['Data'] > df['STD1']) & (df['Data'] < df['STD15'])),
((df['Data'] > df['STD15']) & (df['Data'] < df['STD2'])),
((df['Data'] > df['STD2']) & (df['Data'] < df['STD25'])),
((df['Data'] > df['STD25']) & (df['Data'] < df['STD3'])),
((df['Data'] > df['STD3'])),
((df['Data'] < df['STD-1']) & (df['Data'] > df['STD-15'])),
((df['Data'] < df['STD-15']) & (df['Data'] > df['STD-2'])),
((df['Data'] < df['STD-2']) & (df['Data'] > df['STD-25'])),
((df['Data'] < df['STD-25']) & (df['Data'] > df['STD-3'])),
((df['Data'] < df['STD-3']))
]
result = [0, 1, 1.5, 2, 2.5, 3, -1, -1.5, 2, -2.5, -3]
df['RESULT'] = np.select(condition, result, None) When i Run the code it gets the logic wrong and i do not know why? Marked in yellow what returns wrong answer...
![[Image: MIcSh.jpg]](https://i.stack.imgur.com/MIcSh.jpg)
Can anyone help to find out what I am doing wrong?
