For循环i数据帧基于行而不是列进行计数

问题描述 投票:0回答:1

我有一个大的数据框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

我有一个大数据框df,我正在尝试进行一些计算,当我在计算前打印数据框df时,它看起来像这样:日期高低...关闭...

python pandas dataframe
1个回答
1
投票
尝试
© www.soinside.com 2019 - 2024. All rights reserved.