我有一个使用以下代码的DataFrame:
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/moment-with-locales.min.js"></script>
输出如下:
import pandas as pd
import numpy as np
index = pd.DatetimeIndex(['2017-05-04', '2017-05-05', '2017-05-08', '2017-05-09',
'2017-05-10'], dtype='datetime64[ns]',name = 'date', freq='B')
columns = pd.MultiIndex(levels=[['HSBA LN Equity', 'UCG IM Equity', 'ISP IM Equity'], ['LAST PRICE', 'HIGH', 'LOW']],
labels=[[0, 0, 0, 1, 1, 1, 2, 2, 2], [0, 1, 2, 0, 1, 2, 0, 1, 2]])
data = np.array([[ 663.8, 672.5, 661.1, 15.97, 16.02, 15.49, 2.76, 2.768, 2.694],
[ 658.6, 663.9, 656.0, 16.22, 16.48, 15.77, 2.842, 2.868, 2.77 ],
[ 660.6, 664.1, 658.9, 16.01, 16.49, 15.94, 2.852, 2.898, 2.826],
[ 664.9, 669.2, 662.5, 15.90, 16.41, 15.90, 2.848, 2.898, 2.842],
[ 670.9, 673.4, 663.8, 16.09, 16.15, 15.59, 2.85, 2.888, 2.802]])
df = pd.DataFrame(data, columns=columns, index = index)
当我使用 HSBA LN Equity UCG IM Equity \
LAST PRICE HIGH LOW LAST PRICE HIGH LOW
date
2017-05-04 663.8 672.5 661.1 15.97 16.02 15.49
2017-05-05 658.6 663.9 656.0 16.22 16.48 15.77
2017-05-08 660.6 664.1 658.9 16.01 16.49 15.94
2017-05-09 664.9 669.2 662.5 15.90 16.41 15.90
2017-05-10 670.9 673.4 663.8 16.09 16.15 15.59
ISP IM Equity
LAST PRICE HIGH LOW
date
2017-05-04 2.760 2.768 2.694
2017-05-05 2.842 2.868 2.770
2017-05-08 2.852 2.898 2.826
2017-05-09 2.848 2.898 2.842
2017-05-10 2.850 2.888 2.802
时从Pandas 0.20.1
升级到0.19.2
,输出如下所示:
df = df.stack(0)
列已更改订单,股票价格不再与正确的代码相匹配。
这是一个错误吗?