我如何添加以前的列值以在excel中获得新值?

问题描述 投票:-1回答:2

我正在研究图形,并且需要以下格式的数据。我在Col A中获得数据。我需要如下图所示计算col B值。在Excel中,相同的公式是什么?

enter image description here

python python-3.x excel pandas xlsxwriter
2个回答
0
投票

您可以使用cumsumshift

# sample data
df = pd.DataFrame({'COL A': np.arange(11)})

df['COL B'] = df['COL A'].shift(fill_value=0).cumsum()

输出:

    COL A  COL B
0       0      0
1       1      0
2       2      1
3       3      3
4       4      6
5       5     10
6       6     15
7       7     21
8       8     28
9       9     36
10     10     45

0
投票

使用简单的MS技术。您可以将公式(A3 * A2)/ 2用于COL2

Excel screenshot

© www.soinside.com 2019 - 2024. All rights reserved.