"""Utility functions"""

import os
import pandas as pd

def symbol_to_path(symbol, base_dir="data"):
    """Return CSV file path given ticker symbol."""
    return os.path.join(base_dir, "{}.csv".format(str(symbol)))


def get_data(symbols, dates):
    """Read stock data (adjusted close) for given symbols from CSV files."""
    df = pd.DataFrame(index=dates)
    if 'SPY' not in symbols:  # add SPY for reference, if absent
        symbols.insert(0, 'SPY')

    for symbol in symbols:
        #Read and join data for each symbol
        df_temp=pd.read_csv(symbol_to_path(symbol),index_col='Date', parse_dates=True,usecols=['Date', 'Adj Close'], na_values=['nan'])
        df_temp=df_temp.rename(columns={'Adj Close':symbol})
        df=df.join(df_temp)
        if symbol=='SPY':
            df=df.dropna(subset=['SPY'])
    return df


def test_run():
    # Define a date range
    dates = pd.date_range('2010-01-22', '2010-01-26')

    # Choose stock symbols to read
    symbols = ['GOOG', 'IBM', 'GLD']
    
    # Get stock data
    df = get_data(symbols, dates)
    print df
    print df.ix['2010-01-01':'2010-01-31']#slice by row range

if __name__ == "__main__":
    test_run()

@@ -1074,24 +1074,25 @@
 rint df%0A    
+#
 print df.ix%5B
@@ -1136,16 +1136,192 @@
 ow range
+%0A    #print df%5B'GOOG'%5D#single column%0A    #print df%5B%5B'IBM','GLD'%5D%5D# a list of multiple columns%0A    # print df.ix%5B'2010-01-01':'2010-01-31',%5B'SPY','IBM'%5D%5D#slice by row and column
 %0A%0Aif __n

Create building_df.py