pandas_datareader.data

>>> import numpy as np
>>> import pandas as pd
>>> import pandas.io.data as web
Traceback (most recent call last):
  File "", line 1, in 
    import pandas.io.data as web
ModuleNotFoundError: No module named 'pandas.io.data'
>>> import pandas_datareader.data as web
Traceback (most recent call last):
  File "", line 1, in 
    import pandas_datareader.data as web
ModuleNotFoundError: No module named 'pandas_datareader'

打开cmd,安装pandas-datareader
pip install pandas-datareader

>>> import pandas_datareader.data as web
>>> dir(web)
['AVForexReader', 'AVQuotesReader', 'AVSectorPerformanceReader', 'AVTimeSeriesReader', 'BankOfCanadaReader', 'DEP_ERROR_MSG', 'DataReader', 'EnigmaReader', 'EurostatReader', 'FamaFrenchReader', 'FredReader', 'GoogleDailyReader', 'GoogleOptions', 'GoogleQuotesReader', 'IEXDailyReader', 'IEXDeep', 'IEXLasts', 'IEXTops', 'ImmediateDeprecationError', 'MoexReader', 'MorningstarDailyReader', 'OECDReader', 'Options', 'QuandlReader', 'RobinhoodHistoricalReader', 'RobinhoodQuoteReader', 'StooqDailyReader', 'TiingoDailyReader', 'TiingoQuoteReader', 'YahooActionReader', 'YahooDailyReader', 'YahooDivReader', 'YahooOptions', 'YahooQuotesReader', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'get_components_yahoo', 'get_dailysummary_iex', 'get_data_alphavantage', 'get_data_enigma', 'get_data_famafrench', 'get_data_fred', 'get_data_google', 'get_data_moex', 'get_data_morningstar', 'get_data_quandl', 'get_data_robinhood', 'get_data_stooq', 'get_data_tiingo', 'get_data_yahoo', 'get_data_yahoo_actions', 'get_exchange_rate_av', 'get_iex_book', 'get_iex_symbols', 'get_last_iex', 'get_markets_iex', 'get_nasdaq_symbols', 'get_quote_av', 'get_quote_google', 'get_quote_yahoo', 'get_quotes_robinhood', 'get_quotes_tiingo', 'get_recent_iex', 'get_records_iex', 'get_sector_performance_av', 'get_summary_iex', 'get_tops_iex', 'warnings']
>>> data = web.get_data_yahoo("SPY", start="2017-01-01", end="2017-04-30")
>>> data.head()
                  High         Low  ...       Volume   Adj Close
Date                                ...                         
2017-01-03  225.830002  223.880005  ...   91366500.0  214.830276
2017-01-04  226.750000  225.610001  ...   78744400.0  216.108322
2017-01-05  226.580002  225.479996  ...   78379000.0  215.936646
2017-01-06  227.750000  225.899994  ...   71559900.0  216.709229
2017-01-09  227.070007  226.419998  ...   46939700.0  215.993881

>>> data1 = web.get_data_yahoo(["SPY", "IWM"], start="2017-01-01", end="2017-04-30")
>>> data1.head()
Attributes        High              ...   Adj Close            
Symbols            IWM         SPY  ...         IWM         SPY
Date                                ...                        
2017-01-03  136.830002  225.830002  ...  131.320374  214.830276
2017-01-04  137.960007  226.750000  ...  133.510330  216.108322
2017-01-05  137.759995  226.580002  ...  131.969589  215.936646
2017-01-06  136.710007  227.750000  ...  131.485077  216.709229
2017-01-09  135.720001  227.070007  ...  130.622665  215.993881

[5 rows x 12 columns]
>>> import pandas_datareader.data as web
>>> import pandas as pd
>>> sym = "BABA"
>>> finace = web.DataReader(sym, "yahoo", start="2014/11/11")
>>> finace.tail(3)
                  High         Low  ...    Volume   Adj Close
Date                                ...                      
2019-08-05  157.229996  151.850006  ...  28912600  153.669998
2019-08-06  158.729996  156.110001  ...  24996300  157.429993
2019-08-07  159.479996  155.300003  ...  17555900  159.169998

[3 rows x 6 columns]
>>> import matplotlib.pyplot as plt
>>> plt.plot(finace.index, finace["Open"])
[]
>>> plt.show()

Figure_1.png

https://pandas-datareader.readthedocs.io/en/latest/index.html

你可能感兴趣的:(pandas_datareader.data)