I'm trying to figure out how to use the value from last column of Y with multiple conditions to derive Z and P.
- when Y is between 2 to 6 = last column Z + 5,
- when Y is 1, next column Z = 0 + 5,
- when Y is between 2 to 6, column Q = 0,
- when Y is 1, column Q = X multiple by Z
Original DF:
╔════╦═══╗ ║ X ║ Y ║ ╠════╬═══╣ ║ 29 ║ 5 ║ ║ 28 ║ 4 ║ ║ 32 ║ 3 ║ ║ 29 ║ 3 ║ ║ 26 ║ 1 ║ ║ 38 ║ 5 ║ ║ 25 ║ 2 ║ ║ 33 ║ 3 ║ ║ 25 ║ 3 ║ ║ 25 ║ 5 ║ ║ 40 ║ 1 ║ ║ 30 ║ 6 ║ ║ 31 ║ 3 ║ ║ 38 ║ 5 ║ ╚════╩═══╝
Output needed:
╔════╦═══╦═════╦══════╗ ║ X ║ Y ║ Z ║ P ║ ╠════╬═══╬═════╬══════╣ ║ 29 ║ 5 ║ 5 ║ 0 ║ ║ 28 ║ 4 ║ 10 ║ 0 ║ ║ 32 ║ 3 ║ 15 ║ 0 ║ ║ 29 ║ 3 ║ 20 ║ 0 ║ ║ 26 ║ 1 ║ 25 ║ 650 ║ ║ 38 ║ 5 ║ 5 ║ 0 ║ ║ 25 ║ 2 ║ 10 ║ 0 ║ ║ 33 ║ 3 ║ 15 ║ 0 ║ ║ 25 ║ 3 ║ 20 ║ 0 ║ ║ 25 ║ 5 ║ 25 ║ 0 ║ ║ 40 ║ 1 ║ 30 ║ 1200 ║ ║ 30 ║ 6 ║ 5 ║ 0 ║ ║ 31 ║ 3 ║ 10 ║ 0 ║ ║ 38 ║ 5 ║ 15 ║ 0 ║ ╚════╩═══╩═════╩══════╝
i've did some research and found that shifted is used, however, i can't figure out how to add the other conditions
data = {'X':[29,28,32,29,26,38,25,33,25,25,40,30,31,38], 'Y':[5,4,3,3,1,5,2,3,3,5,1,6,3,5]}
Many thanks