1

I have a data frame of some registered velocities (V1, V2, V3, MaxV or the maximum velocity) and the corresponding time stamps for each velocity(T1, T2, T3, MaxV_T or the time instant of the maximum velocity) as follows:

df

Event T1       V1    T2       V2    T3       V3    MaxV  MaxV_T
  0   12:40:44 42.86 12:40:43 45.65 12:40:39 50.5  50.5  T3
  1   15:28:15 88.75 15:28:14 86.45 15:28:17 84.56 88.75 T1

The point that in the MaxV_T column doesn't indicate the real value but the title of the column where the real value falls.

What i need to do in python is to replace this value with the real time stamp to be like this

df

Event T1       V1    T2       V2    T3       V3    MaxV  MaxV_T
  0   12:40:44 42.86 12:40:43 45.65 12:40:39 50.5  50.5  12:40:39
  1   15:28:15 88.75 15:28:14 86.45 15:28:17 84.56 88.75 15:28:15

UPDATE

What to do if the position indication is not available, so i don't have the initial MaxV_T column and i need to return the corresponding time value for each velocity?

1 Answer 1

3

Use lookup

df.assign(MaxV_T=df.lookup(df.index, df.MaxV_T))

   Event        T1     V1        T2     V2        T3     V3   MaxV    MaxV_T
0      0  12:40:44  42.86  12:40:43  45.65  12:40:39  50.50  50.50  12:40:39
1      1  15:28:15  88.75  15:28:14  86.45  15:28:17  84.56  88.75  15:28:15
Sign up to request clarification or add additional context in comments.

2 Comments

I have an update for the question. What to do if the position indication is not available, so i don,t have the column MaxV_T and i need to return the corresponding time value for each velocity?
@Mshendy I'm confused about what you want. I'd suggest a new question where you can explain the "position not available " more clearly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.