我是python的新手,所以我需要問這個問題:
我有這個資料框:

我需要知道如何通過這個結果獲得一個新的資料框:

從第二行(索引 1)開始,要應用的公式是:
previous row cell value *(1 actual cell value)。
uj5u.com熱心網友回復:
您可以計算第一次使用后的行的累積乘積.cumprod()。在這里,我從第二行開始,將這些加 1 并計算累積乘積。然后我將它乘以第一行。
(df.iloc[1:] 1).cumprod() * df.iloc[0]
然后使用以下方法將資料框的第一行df.head(1)與計算的資料框連接起來pd.concat():
pd.concat([df.head(1), ((df.iloc[1:] 1).cumprod() * df.iloc[0])], ignore_index=True)
這可以分成幾部分:
# calculation
df2 = (df.iloc[1:] 1).cumprod() * df.iloc[0]
# concatenate the first row of df with the calculation
pd.concat([df.head(1), df2], ignore_index=True)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/473807.html
上一篇:如何檢查牌組中第一張面卡的位置?
