擅长:python、mysql、java
<p>您应该能够通过使用文档中的<code>pandas.pivot_table()</code>功能来完成您想要做的事情<a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.pivot_table.html" rel="nofollow noreferrer" title="pandas.pivot_table()">here</a>。在</p>
<p>将数据帧存储为<code>df</code>时,请使用以下代码:</p>
<pre><code>import pandas as pd
df = pd.read_table('table_from_which_to_read')
new_df = pd.pivot_table(df,index=['Simple Name'], columns = 'Component_Name', values = "Calculated_Concentration")
</code></pre>
<p>如果您想要的不是浓度值的平均值,则需要更改<code>aggfunc</code>参数。在</p>
<p><strong>编辑</strong></p>
<p>因为您不想聚集这些值,所以您可以通过在DataFrame上使用<code>set_index</code>函数来重塑数据,并找到文档<a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow noreferrer">here</a>。在</p>
^{pr2}$
<p>结果表应该看起来像您期望的结果,并且将有一个多索引。在</p>