考慮我有具有兩列A和B 10行的數據幀如下:大熊貓 - 指數加權移動平均 - 類似練成
A B
0 21 6
1 87 0
2 87 0
3 25 0
4 25 0
5 14 0
6 79 0
7 70 0
8 54 0
9 35 0
在Excel我可以計算rolling
mean
這樣不包括第一行:
我該如何在熊貓中做到這一點?
這裏是我試過:
import pandas as pd
df = pd.read_clipboard() #copying the dataframe given above and calling read_clipboard will get the df populated
for i in range(1, len(df)):
df.loc[i, 'B'] = df[['A', 'B']].loc[i-1].mean()
這給了我匹配的Excel期望的結果。但是有更好的熊貓方法嗎?我試過使用expanding
和rolling
沒有產生預期的結果。
我對你在這裏瞄準的目標有些困惑。例如,窗口長度爲2的系列A的「標準」移動平均值在單元格B2中具有公式= AVERAGE(A2:A1),而不是= AVERAGE(A1,B1)鑑於您已經接受一個答案,我假設你已經得到了你以前的樣子,但是如果你有時間提供一些細節,那將是很酷的。 – vestland
我正在嘗試製作Heiken-Ashi蠟燭。當前欄開盤價格是前一欄的開盤價和平倉價的平均值。有關更多詳細信息,請參閱此鏈接https://www.quantiacs.com/Blog/Intro-to-Algorithmic-Trading-with-Heikin-Ashi.aspx – Abbas