https://i.stack.imgur.com/jsILy.png(我在Jupyter上的代码截图)
import numpy as np
import pandas as pd
from pandas_datareader import data as wb
import matplotlib.pyplot as plt
tickers = ['PG', 'MSFT', 'F', 'GE']
mydata = pd.DataFrame()
for t in tickers:
mydata[t] = wb.DataReader(t, data_source='morningstar', start = '2005-1-1')['Close']
mydata.info()
给出:
<class 'pandas.core.frame.DataFrame'>
MultiIndex: 3430 entries, (PG, 2005-01-03 00:00:00) to (PG, 2018-02-23 00:00:00)
Data columns (total 4 columns):
PG 3430 non-null float64
MSFT 0 non-null float64
F 0 non-null float64
GE 0 non-null float64
dtypes: float64(4)
memory usage: 144.1+ KB
附上我用来获取这些股票收盘价数据的代码。但是,在第一个股票之后,我继续遇到所有股票的NaN问题。它没有显示数据。我不知道我做错了什么。此外,我正在使用晨星,因为雅虎或谷歌都没有与Jupyter兼容,原因有些奇怪。任何帮助表示赞赏!