Collecting financial data
Back in Chapter 2, Working with Pandas DataFrames, and Chapter 3, Data Wrangling with Pandas, we worked with APIs to gather data; however, there are other ways to collect data from the Internet. We can use web scraping to extract data from the HTML page itself, which pandas
offers with the pd.read_html()
function—it returns a dataframe for each of the HTML tables it finds on the page. For economic and financial data, an alternative is the pandas_datareader
package, which the StockReader
class in the stock_analysis
package uses to collect financial data.
Important note
In case anything has changed with the data sources that are used in this chapter or you encounter errors when using the StockReader
class to collect data, the CSV files in the data/
folder can be read in as a replacement in order to follow along with the text; for example:
pd.read_csv('data/bitcoin.csv', index_col='date',
parse_dates=True...