【发布时间】:2020-12-24 09:13:04
【问题描述】:
我有两个字典,每个字典有 206 个条目。每个团队都是一个数据框。查看图像以了解其中的词典和项目。
我想将所有“电压”字典中的容量值替换如下
x = (total number of rows in the sheet )/25
Capacity Value in Row1(index=0) - the sum of the values from Rows 1 to x in
"Current" column of 'copy'
Capacity Value in Row2(index=1) - the sum of the values from Rows x to 2*x in
"Current" column of 'copy'
Capacity Value in Row3(index=2) - the sum of the values from Rows 2*x to 3*x
in "Current" column of 'copy'
.
.
.
Capacity Value in Row25(index=24) - the sum of the values from Rows 24*x to
the last value.
为此,我编写了如下代码:
for sheet in voltage:
for sheet in copy:
n = ( round((len(copy[sheet]))/25) )
for k in range(0,24):
p = 1+((k+1)*(n))
if k == 24:
voltage[sheet]['Capacity'].iloc[k] = copy[sheet]['Current'].iloc[((k)*(n)):].sum()
else:
voltage[sheet]['Capacity'].iloc[k] = copy[sheet]['Current'].iloc[((k)*(n)+1):(p)].sum()
它显示相同的错误消息。请帮助我。
错误消息:“单个位置索引器超出范围”
谢谢你:)
【问题讨论】:
标签: python excel dataframe dictionary for-loop