<p>我假设您想添加2个额外的列,您可以这样做:
首先添加两列,其中填充0个值(或任意值),然后使用舍入/舍入公式更新这些值</p>
<pre><code>roundposnew['Rounded up'] = 0.
roundposnew['Rounded down'] = 0.
for i in df.columns:
fal = df.columns.get_loc(i)
ld5 = df.iloc[int(roundposnew.loc[i,'Round Down']-1),int(fal)]
ld6 = df.iloc[int(roundposnew.loc[i, 'Round Up'] + 1), int(fal)]
roundposnew.loc[i,'Rounded down'] = ld5
roundposnew.loc[i, 'Rounded up'] = ld6
print('values for '+i+' are: \n rounded down: '+str(ld5)+' \n rounded up: '+str(ld6))
print(roundposnew)
</code></pre>
<p>输出如下所示:</p>
<pre><code> Observations Round Down Round Up Rounded up Rounded down
GDPs
Italian GDP 89 1.0 2.0 -0.051142 -0.057750
US GDP 281 5.0 6.0 -0.000720 -0.005046
EA GDP 89 1.0 2.0 0.014639 0.009119
FR GDP 169 3.0 4.0 -0.005746 -0.009310
DE GDP 105 2.0 3.0 -0.010145 -0.023653
CZ GDP 85 1.0 2.0 -0.006948 -0.017287
HU GDP 89 1.0 2.0 -0.057246 -0.068923
UK GDP 169 3.0 4.0 -0.024922 -0.027973
NL GDP 85 1.0 2.0 -0.008191 -0.011381
RO GDP 89 1.0 2.0 -0.073923 -0.082121
</code></pre>
<p>希望这能给你一个解决问题的方法</p>