第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Pandas 中找到當前和先前移動平均線交叉之間的最小值

在 Pandas 中找到當前和先前移動平均線交叉之間的最小值

狐的傳說 2021-10-12 17:22:04
我有一個包含股票價格數(shù)據(jù)的大型數(shù)據(jù)框 df.columns = ['open','high','low','close']問題定義:當 EMA 交叉發(fā)生時,我提到 df['cross'] = cross。每次發(fā)生交叉時,如果我們將當前交叉標記為 crossover4,我想檢查交叉 3 和交叉 4 之間 df['low'] 的最小值是否大于交叉 1 之間的 df['low'] 最小值和 2. 我已經(jīng)根據(jù)迄今為止從“Gherka”收到的幫助嘗試編寫代碼。我已經(jīng)索引了交叉并找到了連續(xù)交叉之間的最小值。因此,每次發(fā)生交叉時,都必須與前 3 次交叉進行比較,我需要檢查 MIN(CROSS4,CROSS 3) > MIN(CROSS2,CROSS1)。如果你們能幫我完成,我將不勝感激。import pandas as pd    import numpy as np    import bisect as bsdata = pd.read_csv("Nifty.csv")    df = pd.DataFrame(data)    df['5EMA'] = df['Close'].ewm(span=5).mean()    df['10EMA'] = df['Close'].ewm(span=10).mean()    condition1 = df['5EMA'].shift(1) < df['10EMA'].shift(1)    condition2 = df['5EMA'] > df['10EMA']    df['cross'] = np.where(condition1 & condition2, 'cross', None)    cross_index_array = df.loc[df['cross'] == 'cross'].indexdef find_index(a, x):        i = bs.bisect_left(a, x)        return a[i-1]def min_value(x):    """Find the minimum value of 'Low' between crossovers 1 and 2, crossovers 3 and 4, etc..."""        cur_index = x.name        prev_cross_index = find_index(cross_index_array, cur_index)        return df.loc[prev_cross_index:cur_index, 'Low'].min()df['min'] = None    df['min'][df['cross'] == 'cross'] = df.apply(min_value, axis=1)    print(df)
查看完整描述

1 回答

?
拉風的咖菲貓

TA貢獻1995條經(jīng)驗 獲得超2個贊

這應該可以解決問題:


import pandas as pd


df = pd.DataFrame({'open': [1, 2, 3, 4, 5],

                   'high': [5, 6, 6, 5, 7],

                   'low': [1, 3, 3, 4, 4],

                   'close': [3, 5, 3, 5, 6]})


df['day'] = df.apply(lambda x: 'bull' if (

    x['close'] > x['open']) else None, axis=1)


df['min'] = None

df['min'][df['day'] == 'bull'] = pd.rolling_min(

    df['low'][df['day'] == 'bull'], window=2)


print(df)


#    close  high  low  open   day   min

# 0      3     5    1     1  bull   NaN 

# 1      5     6    3     2  bull     1

# 2      3     6    3     3  None  None

# 3      5     5    4     4  bull     3

# 4      6     7    4     5  bull     4

開放評論!


查看完整回答
反對 回復 2021-10-12
  • 1 回答
  • 0 關注
  • 218 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號