<p><a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.unstack.html" rel="nofollow noreferrer">Unstack</a>可用于将宽格式转换为长格式(相反的函数是<code>pivot</code>)。在</p>
<pre><code>>> import pandas as pd
>> from io import StringIO
>> csv = StringIO(u'''style VALUE GROWTH QUALITY QUALITY
factor EarningsYield OPER_MARGIN RETURN_COM_EQY GEARING
VEDG LX Equity NaN 18.604873 NaN 1.04020
DPW DU Equity 0.057845 36.001430 10.957723 0.438649e''')
>> df = pd.read_csv(csv, sep='\t', header=[0, 1], index_col=0)
>> df
style VALUE GROWTH QUALITY
factor EarningsYield OPER_MARGIN RETURN_COM_EQY GEARING
VEDG LX Equity NaN 18.604873 NaN 1.04020
DPW DU Equity 0.057845 36.001430 10.957723 0.438649e
>> df.unstack()
style factor
VALUE EarningsYield VEDG LX Equity NaN
DPW DU Equity 0.057845
GROWTH OPER_MARGIN VEDG LX Equity 18.6049
DPW DU Equity 36.0014
QUALITY RETURN_COM_EQY VEDG LX Equity NaN
DPW DU Equity 10.9577
GEARING VEDG LX Equity 1.04020
DPW DU Equity 0.438649e
</code></pre>
<p>要想得到你的确切格式,你得先玩一会儿。在</p>