I have a dataframe as below. Based on few conditions, I need to retrive the column.
Wifi_User1 Wifi_User2 Wifi_User3 Thermostat Act_User1 Act_User2 Act_User3
-58 -48 -60 18 0 1 0
-60 -56 -75 18 0 1 1
-45 -60 -45 18 0 1 1
-67 -45 -60 18 1 0 1
-40 -65 -65 18 1 0 1
-55 -78 -74 18 1 0 0
-55 -45 -65 18 1 0 0
-67 -45 -44 18 0 0 0
-65 -68 -70 18 0 0 0
-70 -70 -65 24 0 0 0
-72 -56 -45 24 0 1 0
-75 -45 -60 24 0 1 0
-77 -48 -65 24 0 0 0
The conditions are as follows:
if (Wifi_User1==Wifi_User2) or (Wifi_User2==Wifi_User3)
or (Wifi_User3==Wifi_User1) or (Wifi_User1==Wifi_User2==Wifi_User3)
and when the thermostat value is changing
then
scan Act_User1, Act_User2, Act_User3 columns for the first instance of 1
before the thermostat value changes.
If its Act_user1, return 1
else if its Act_User2 return 2
else return 3
For example, in the above dataset, at 10th row Wifi_user1 == Wifi_User2 and the thermostat value is changing from 18 to 24.
For this condition, I will scan Act_User1, Act_User2, Act_User3. And see that, the first instance of 1 occurs for Act_User1, hence I need to return the value 1 in the new column for this particular row.
Please help me as how to go about it, as I'm new to Python and exploring python