Data Collection from the Web

# -*- coding: utf-8 -*-
"""
Created on Sun Jan  5 11:02:36 2020

@author: Bruce1
"""

# =======================================================================
# Import Pandas Library
# =======================================================================
import pandas as pd 
import pandas_datareader.data as web

# =======================================================================
# Setup Variables to data fetch
# =======================================================================
sym = 'GLD'

startDate = '01/01/2000'
endDate   = '12/31/2019'

# =======================================================================
# Gather data in Loop
# =======================================================================
symList = ["SPY", "GLD", "TLT"]

for sym in symList:
    
# =======================================================================
# Gather data
# =======================================================================
    print("")
    print("-> Fetching data from the web")

    df = web.DataReader(sym, data_source='yahoo', start=startDate, end=endDate)

# =======================================================================
# Inspect/Report on data
# =======================================================================
    firstIndex = df.index.min()
    lastIndex = df.index.max()
    records = len(df)
    print("")
    print("-> Importing ", sym)
    print("First Date = ", firstIndex)
    print("Last Date  = ", lastIndex)
    print("Total Days = ", records)

    if df.isnull().values.any() == True:
        print("WARNING: there are {} NaN in the data".format(df.isnull().values.sum()))
        print(df.isnull().values)
    
    print(df.describe())

# =======================================================================
# Store data
# =======================================================================
    #df.to_csv("{}.csv".format(sym))
    df.to_excel("{}.xlsx".format(sym))