当我在iPython
中运行此代码时,它完美无缺。但是当我从终端运行相同的脚本时,我收到一条错误消息:AttributeError: 'NoneType' object has no attribute 'unstack'
import pandas as pd
import pandas.io.data as web
stocks = {'xom': '2015-01-01', 'aapl': '2014-01-01', 'dvn': '2013-01-01'}
def fetch_data_from_yahoo(d_stocks):
df_list = []
for symbol, start_date in d_stocks.items():
df_list.append(web.get_data_yahoo(symbol, start_date)['Adj Close'])
return pd.concat(df_list, keys=list(d_stocks.keys()))
fetch_data_from_yahoo(stocks)
fetch_data_from_yahoo(stocks).unstack(0)