如何将三个不同系列的最小值存储在一个新系列中?
How to store the minimum value of three different Series in a new Series?
这是代码:
import yfinance as yf
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
ticker = "EURUSD=X"
df = yf.download(ticker, start='2021-1-1', interval='1h')
df['MA30'] = df.Close.rolling(30).mean()
df['MA60'] = df.Close.rolling(60).mean()
df['MA120'] = df.Close.rolling(120).mean()
df['ADX'] = ta.trend.ADXIndicator(df.High, df.Low, df.Close, window=14).adx()
df = df.dropna()
如何获取 MA30、MA60 和 MA120 中的最小值(每行)并将其存储在一个新列中,我可以称之为“ma_min”?
谢谢
new_col = df.apply(lambda row: min(row["MA30"], row["MA60"], row["MA120"]), axis=1)
df["mins"] = new_col
import yfinance as yf
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 150)
ticker = "EURUSD=X"
df = yf.download(ticker, start='2021-1-1',interval='1h')
df['MA30'] = df['Close'].rolling(window=30).mean()
df['MA60'] = df['Close'].rolling(window=60).mean()
df['MA120'] = df['Close'].rolling(window=120).mean()
df['ma_min'] = df[['MA30','MA60', 'MA120']].min(axis=1)
print(df.head(400))
这是代码:
import yfinance as yf
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
ticker = "EURUSD=X"
df = yf.download(ticker, start='2021-1-1', interval='1h')
df['MA30'] = df.Close.rolling(30).mean()
df['MA60'] = df.Close.rolling(60).mean()
df['MA120'] = df.Close.rolling(120).mean()
df['ADX'] = ta.trend.ADXIndicator(df.High, df.Low, df.Close, window=14).adx()
df = df.dropna()
如何获取 MA30、MA60 和 MA120 中的最小值(每行)并将其存储在一个新列中,我可以称之为“ma_min”? 谢谢
new_col = df.apply(lambda row: min(row["MA30"], row["MA60"], row["MA120"]), axis=1)
df["mins"] = new_col
import yfinance as yf
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 150)
ticker = "EURUSD=X"
df = yf.download(ticker, start='2021-1-1',interval='1h')
df['MA30'] = df['Close'].rolling(window=30).mean()
df['MA60'] = df['Close'].rolling(window=60).mean()
df['MA120'] = df['Close'].rolling(window=120).mean()
df['ma_min'] = df[['MA30','MA60', 'MA120']].min(axis=1)
print(df.head(400))