Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
logic python
#1
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.

 
#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]

Can anyone help to find out what I am doing wrong?
Reply


Messages In This Thread
logic python - by JunkBoy - Jul-28-2022, 07:19 AM
RE: logic python - by Larz60+ - Jul-28-2022, 09:22 AM
RE: logic python - by JunkBoy - Jul-29-2022, 04:55 AM
RE: logic python - by buran - Jul-29-2022, 06:00 AM
RE: logic python - by Pedroski55 - Jul-29-2022, 08:23 AM
RE: logic python - by JunkBoy - Aug-01-2022, 05:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Logic Error rmfooty 3 968 Dec-05-2022, 01:44 PM
Last Post: rmfooty
  (Python help) Change in logic not breaking 'while' loop? btcg2807 1 1,915 Sep-18-2019, 09:43 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020