python使用问题 "The pandas.io.data module is moved to a separate package "

时间:2021-01-10 15:31:52
 1 import pandas as pd
 2 import datetime
 3 import pandas.io.data as web
 4 import matplotlib.pyplot as plt
 5 from matplotlib import style
 6 
 7 style.use('ggplot') 8 
 9 start = datetime.datetime(2010,1,1)
10 end = datetime.datetime(2015,1,1)
11 
12 df = web.DataReader("XOM","yahoo",start,end)
13 
14 print(df.head())
15 
16 df['Adj Close'].plot()
17 
18 plt.show()

 

问题:

"C:\Program Files\Anaconda3\python.exe" C:/Users/Administrator/PycharmProjects/untitled1/new.py
Traceback (most recent call last):
File "C:/Users/Administrator/PycharmProjects/untitled1/new.py", line 3, in <module>
import pandas.io.data as web
File "C:\Program Files\Anaconda3\lib\site-packages\pandas\io\data.py", line 2, in <module>
"The pandas.io.data module is moved to a separate package "
ImportError: The pandas.io.data module is moved to a separate package (pandas-datareader). After installing the pandas-datareader package (https://github.com/pandas-dev/pandas-datareader), you can change the import ``from pandas.io import data, wb`` to ``from pandas_datareader import data, wb``.

Process finished with exit code 1

 

解决:

1、安装pandas-datareader

pip install pandas-datareader
2、修改代码

import pandas.io.data as web

改为
import pandas_datareader.data as web

import pandas as pd
import datetime
import pandas_datareader.data as web
import matplotlib.pyplot as plt
from matplotlib import style

style.use('ggplot')

start = datetime.datetime(2010,1,1)
end = datetime.datetime(2015,1,1)

df = web.DataReader("XOM","yahoo",start,end)

print(df.head())

df['Adj Close'].plot()

plt.show()

python使用问题 "The pandas.io.data module is moved to a separate package "