Vlookup 用 python 数据框中每一行的值替换列索引

Vlookup to replace column index with value for each row in python dataframes

我有一些注册速度(V1、V2、V3、MaxV 或最大速度)的数据帧以及每个速度的相应时间戳(T1、T2、T3、MaxV_T 或时间最大速度的瞬间)如下:

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

MaxV_T 列中的要点不是表示实际值,而是表示实际值所在列的标题。

我在python中需要做的是将这个值替换为实时时间戳,就像这样

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

更新

如果位置指示不可用怎么办,所以我没有初始 MaxV_T 列,我需要 return 每个速度的相应时间值?

使用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