我想将Ticker列添加为名为df_main的数据框的索引,该数据框具有DatetimeIndex,如下所示:
open high low close Ticker
Date
2017-04-18 46.3100 46.3150 46.1520 46.1520 AADR
2017-04-19 46.4000 46.5190 46.0600 46.0600 AADR
2017-04-22 47.3092 47.8500 46.6000 47.6200 AADR
2017-04-23 47.9000 48.7100 47.5900 47.5900 AADR
2017-04-24 47.5000 50.0300 47.0001 47.0001 AADR
2017-04-25 47.0600 48.1000 47.0000 48.1000 AADR
2017-04-26 47.3400 47.3400 47.0495 47.1200 AADR
2017-04-29 47.3400 47.6800 47.1844 47.6800 AADR
2017-04-30 47.8400 47.8400 47.4300 47.4800 AADR
2017-05-01 47.7200 47.9400 47.4700 47.9300 AADR
2017-05-02 47.3700 48.2000 47.1262 48.2000 AADR
我尝试了几件事但没有人认出'Date'是当前索引的名称。
尝试1('日期'错误):
tuples = df_main['Ticker'], df_main['Date']
df_index = pd.MultiIndex.from_tuples(tuples, names=['Ticker', 'Date'])
df_main.index = df_index
尝试2('日期'错误):
df_main = df_main.reindex(index = [df_main.Ticker, df_main.Date])
任何帮助将不胜感激!