回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有以下几点:</p>
<pre><code>dictionary = {'col1': ["England", "USA","Germany","Canada","Cuba","Vietnam"], 'col2':
["France", "Spain","Italy","Jamaica","Bulgaria","South Korea"],
"rating":[2,4,-5,2,1,2],"value":[1,1,2,2,3,3]}
table=pd.DataFrame(dictionary)
</code></pre>
<p>从而产生以下输出:</p>
<pre><code> col1 col2 rating value
0 England France 2 1
1 USA Spain 4 1
2 Germany Italy -5 2
3 Canada Jamaica 2 2
4 Cuba Bulgaria 1 3
5 Vietnam South Korea 2 3
</code></pre>
<p>我有三个系列的单子。你知道吗</p>
<pre><code>list([pd.Series([50,2],["const","Match Rating"]),
pd.Series([48,2],["const","Match Rating"]),
pd.Series([47,2.5],["const","Match Rating"])])
</code></pre>
<p>看起来是这样的</p>
<pre><code>[const 50
Match Rating 2
dtype: int64,
const 48
Match Rating 2
dtype: int64,
const 47
Match Rating 2.5
dtype: int64]
</code></pre>
<p>我想在数据框中创建一个名为“result”的列,其中应用了一个公式。<code>Rating (from the dataframe) * match rating (from the list) + const (from the list)</code>
当dataframe中的“value”为1时,应应用列表中的第一组元素,即50和2。当dataframe的“value”为2时,应应用第二组元素,即48和2,依此类推。你知道吗</p>
<p>预期结果如下:</p>
<pre><code>col1 col2 rating value result
England France 2 1 54
USA Spain 4 1 58
Germany Italy -5 2 38
Canada Jamaica 2 2 52
Cuba Bulgaria 1 3 49.5
Vietnam South Korea 2 3 52
</code></pre>
<p>提前谢谢</p>