Python 如何获得42天S&;的滚动平均值;P 500使用熊猫?
您可以使用Python 如何获得42天S&;的滚动平均值;P 500使用熊猫?,python,pandas,quantitative-finance,Python,Pandas,Quantitative Finance,您可以使用rolling()后跟mean() 请将您的问题标题改为突出显示“熊猫的滚动平均值”您需要解释您实际遇到的问题。仅凭此错误消息很难提供帮助。 import numpy as np import pandas as pd df = pd.DataFrame(np.random.randint(0,100, size=(100, 1)), columns=['close_price']) df['rolling_mean_42d'] = df['close_price'].rolling
rolling()
后跟mean()
请将您的问题标题改为突出显示“熊猫的滚动平均值”您需要解释您实际遇到的问题。仅凭此错误消息很难提供帮助。
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randint(0,100, size=(100, 1)), columns=['close_price'])
df['rolling_mean_42d'] = df['close_price'].rolling(window=42).mean()
df
import numpy as np
import pandas as pd
df = pd.DataFrame(np.random.randint(0,100, size=(100, 1)), columns=['close_price'])
df['rolling_mean_42d'] = df['close_price'].rolling(window=42).mean()
df
sp500['42d'] = sp500['Close'].rolling(window=42).mean()