擅长:python、mysql、java
<p>所以,有礼貌的做法是形成你的问题,这样贡献者就可以很容易地运行你的代码。</p>
<pre><code>import pandas as pd
y_col = [880.37, 716.20, 974.79, 322.80, 1054.25]
x1_col = [3.17, 4.76, 4.17, 8.70, 11.45]
x2_col = [23, 26, 73, 72, 16]
df = pd.DataFrame()
df['y'] = y_col
df['x1'] = x1_col
df['x2'] = x2_col
</code></pre>
<p>然后调用<code>df.head()</code>产生:</p>
<pre><code> y x1 x2
0 880.37 3.17 23
1 716.20 4.76 26
2 974.79 4.17 73
3 322.80 8.70 72
4 1054.25 11.45 16
</code></pre>
<p>现在,对于您的问题,添加具有计算值的列相当简单,尽管我不同意您的示例数据:</p>
<pre><code>df['y_hat'] = df['x1'] + df['x2']
df['res'] = df['y'] - df['y_hat']
</code></pre>
<p>对我来说,这些屈服:</p>
<pre><code> y x1 x2 y_hat res
0 880.37 3.17 23 26.17 854.20
1 716.20 4.76 26 30.76 685.44
2 974.79 4.17 73 77.17 897.62
3 322.80 8.70 72 80.70 242.10
4 1054.25 11.45 16 27.45 1026.80
</code></pre>
<p>希望这有帮助!</p>