Этот код:
# from pandas_datareader import data
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib.pyplot as plt
import fix_yahoo_finance as yf
%matplotlib inline
import seaborn as sns
sns.set_style("darkgrid")
data = yf.download(tickers = ['AAPL' , 'GOOGL'] , start='2016-01-01',end='2018-01-01')
data
data.columns
возвращает:
MultiIndex(levels=[['Adj Close', 'Close', 'High', 'Low', 'Open', 'Volume'], ['AAPL', 'GOOGL']],
labels=[[4, 4, 2, 2, 3, 3, 1, 1, 0, 0, 5, 5], [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]])
Попытка выбора из мультииндекса с помощью:
data.xs('AAPL', level='Adj Close', axis=1)
возвращает:
/opt/conda/lib/python3.6/site-packages/pandas/core/indexes/multi.py in _get_level_number(self, level)
612 except ValueError:
613 if not isinstance(level, int):
--> 614 raise KeyError('Level %s not found' % str(level))
615 elif level < 0:
616 level += self.nlevels
KeyError: 'Level Adj Close not found'
Как выбрать из MultiIndex
pandas dataframe?