我有两个标量变量 A 和 B,还有一个 DataFrame df1,其中有 1000 列和 86400 行。为了简单起见,下表只展示了 10 列:
0 1 2 3 4 5 6 7 8 9 f
0 4.000000 23.000000 6.000000 36.000000 37.000000 33.000000 22.000000 28.000000 8.000000 14.000000 50.135
1 4.002361 23.002361 6.002361 36.002361 37.002361 33.002361 22.002361 28.002361 8.002361 14.002361 50.130
2 4.004722 23.004722 6.004722 36.004722 37.004722 33.004722 22.004722 28.004722 8.004722 14.004722 50.120
3 4.007083 23.007083 6.007083 36.007083 37.007083 33.007083 22.007083 28.007083 8.007083 14.007083 50.112
4 4.009444 23.009444 6.009444 36.009444 37.009444 33.009444 22.009444 28.009444 8.009444 14.009444 50.102
5 4.011806 23.011806 6.011806 36.011806 37.011806 33.011806 22.011806 28.011806 8.011806 14.011806 50.097
... ... ... ... ... ... ... ... ... ... ... ...
86387 207.969306 226.969306 209.969306 239.969306 240.969306 236.969306 225.969306 231.969306 211.969306 217.969306 49.920
86388 207.971667 226.971667 209.971667 239.971667 240.971667 236.971667 225.971667 231.971667 211.971667 217.971667 49.920
86389 207.974028 226.974028 209.974028 239.974028 240.974028 236.974028 225.974028 231.974028 211.974028 217.974028 49.920
86390 207.976389 226.976389 209.976389 239.976389 240.976389 236.976389 225.976389 231.976389 211.976389 217.976389 49.920
86391 207.978750 226.978750 209.978750 239.978750 240.978750 236.978750 225.978750 231.978750 211.978750 217.978750 49.917
86392 207.981111 226.981111 209.981111 239.981111 240.981111 236.981111 225.981111 231.981111 211.981111 217.981111 49.917
86393 207.983472 226.983472 209.983472 239.983472 240.983472 236.983472 225.983472 231.983472 211.983472 217.983472 49.915
86394 207.985833 226.985833 209.985833 239.985833 240.985833 236.985833 225.985833 231.985833 211.985833 217.985833 49.915
86395 207.988194 226.988194 209.988194 239.988194 240.988194 236.988194 225.988194 231.988194 211.988194 217.988194 49.915
86396 207.990556 226.990556 209.990556 239.990556 240.990556 236.990556 225.990556 231.990556 211.990556 217.990556 49.912
86397 207.992917 226.992917 209.992917 239.992917 240.992917 236.992917 225.992917 231.992917 211.992917 217.992917 49.915
86398 207.995278 226.995278 209.995278 239.995278 240.995278 236.995278 225.995278 231.995278 211.995278 217.995278 49.917
86399 207.997639 226.997639 209.997639 239.997639 240.997639 236.997639 225.997639 231.997639 211.997639 217.997639 49.917
我希望执行逐行操作:
当f>50时:将C=A/B/3600添加到1-999列中的值。
当f<50时:从1-999列中的值中减去C=A/B/3600。
cols = df1.columns[df1.columns.isin(range(0, 999))]
df1[cols] = np.where(df1[cols] > 50,
df1[cols].values - np.arange(len(df1))[:, None] * C,
df1[cols].values + np.arange(len(df1))[:, None] * C)
可以看到,即使f<50,值仍然在不断增加。
有什么建议吗? 提前感谢您的回复。