为了账号安全,请及时绑定邮箱和手机立即绑定

Pandas:对 Pandas DataFrame 中的当前和后续单元格求和

Pandas:对 Pandas DataFrame 中的当前和后续单元格求和

慕尼黑5688855 2021-09-11 15:28:35
Python代码import numpy as npimport pandas as pdimport matplotlib.pyplot as pltfrom pandas_datareader import data as wbstock='3988.HK'df = wb.DataReader(stock,data_source='yahoo',start='2018-07-01')rsi_period = 14chg = df['Close'].diff(1)gain = chg.mask(chg<0,0)df['Gain'] = gainloss = chg.mask(chg>0,0)df['Loss'] = lossavg_gain = gain.ewm(com = rsi_period-1,min_periods=rsi_period).mean()avg_loss = loss.ewm(com = rsi_period-1,min_periods=rsi_period).mean()df['Avg Gain'] = avg_gaindf['Avg Loss'] = avg_lossrs = abs(avg_gain/avg_loss)rsi = 100-(100/(1+rs))df['RSI'] = rsidf.reset_index(inplace=True)df在这种情况下,我想创建一个新列“14 个交易日内的最大收盘价”。“14 个交易日内的最大收盘价”=接下来 14 天内的最大“收盘价”。例如,在第 0 行,数据范围应该是从第 1 行到第 15 行,“14 个交易日内的最大收盘价”= 3.86
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 239 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信