我有一个很大的数据框 df ,我要对其进行计算,当我在计算之前打印数据框df时,它看起来像这样:
Date High Low ... Close Volume Adj Close
0 2000-01-03 47.995617 45.515598 ... 45.880310 6471200.0 34.997250
1 2000-01-04 45.479130 43.509705 ... 44.147945 10440800.0 33.675823
2 2000-01-05 44.676769 42.962643 ... 42.962643 8646200.0 32.820454
3 2000-01-06 44.457947 42.452049 ... 43.837940 10990900.0 33.489136
4 2000-01-07 44.786182 43.327351 ... 44.476181 6016400.0 33.976704
... ... ... ... ... ... ... ...
5013 2019-12-05 118.430000 117.589996 ... 118.279999 3128300.0 118.279999
5014 2019-12-06 121.440002 119.910004 ... 120.610001 3287600.0 120.610001
5015 2019-12-09 121.529999 120.110001 ... 120.459999 2885200.0 120.459999
5016 2019-12-10 121.470001 120.029999 ... 120.900002 2518200.0 120.900002
5017 2019-12-11 121.379997 120.099998 ... 120.639999 1885981.0 120.639999
[5018 rows x 7 columns]
现在我要对其进行RSI计算,并将结果添加到数据帧中
def rsi_calculator(df):
last_value = float(df. loc[0, 'Adj Close'])
print(last_value)
for count, row in enumerate(df, start=1):
print(float(df. loc[count, 'Adj Close']))
这还没有完成,但是如何让我的循环运行5018次,这是我的行数,而不是7那是我的列数
34.997249603271484
33.67582321166992
32.82045364379883
33.4891357421875
33.97670364379883
34.450363159179695
34.770755767822266
34.589675903320305
答案 0 :(得分:1)
尝试
for col,row in df.iterrows():
print((col,row["Adj Close"])[1])
至少对我来说,这种技术输出一对项目(一个元组)。 [1]逻辑获得元组中的第二项,即您要查找的值。
祝你好运!