我有以下pandas Dataframe,并希望在行中执行计算,这些行由示例列中字符串值为“NIST”的行包围。
date116/120 117/120 118/120 119/120 122/120 124/120 sample
2015-05-03 15:22:00 0.446305 0.235479 0.743318 0.263526 0.142027 0.177417 NIST 100ppb
2015-05-03 15:31:00 0.446106 0.235352 0.743078 0.263473 0.142046 0.177475 SPEX 100ppb
2015-05-03 15:40:00 0.446238 0.235403 0.743182 0.263491 0.142041 0.177445 NIST 100ppb
2015-05-03 15:48:00 0.446111 0.235356 0.743072 0.263472 0.142048 0.177499 SPEX 100ppb
2015-05-03 15:57:00 0.446259 0.235415 0.743217 0.263511 0.142051 0.177446 NIST 100ppb
计算结果如下:
df = ((df / (df.shift(1) + df.shift(-1)))-1)*1000