ImportOSImportPandas as PDImportMatplotlib.pyplot as PltdefTest_run (): start_date='2017-01-01'End_data='2017-12-15'dates=Pd.date_range (start_date, End_data)#Create an empty data frameDF=PD. DataFrame (index=dates) Symbols=['SPY','AAPL','IBM','GOOG','GLD'] forSymbolinchsymbols:temp=getadjcloseforsymbol (symbol) DF=df.join (temp, how='Inner') returnDFdefGetadjcloseforsymbol (symbol):#Load csv fileTemp=pd.read_csv ("Data/{0}.csv". Format (symbol), Index_col="Date", Parse_dates=True, Usecols=['Date','ADJ Close'], na_values=['nan']) #Rename the columnTemp=temp.rename (columns={'ADJ Close': Symbol}) returnTempdefPlot_data (DF, title="Stock Prices"): Ax=df.plot (Title=title, fontsize=10) Ax.set_xlabel ("Date") Ax.set_ylabel (" Price") plt.show ()if __name__=='__main__': DF=Test_run ()#data=data.ix[' 2017-12-01 ': ' 2017-12-15 ', [' IBM ', ' GOOG ']plot_data (DF)"""IBM GOOG 2017-12-01 154.759995 1010.169983 2017-12-04 156.460007 998.679993 2017-12-05 155.350006 1005.150024 2017-12-06 154.100006 1018.380005 2017-12-07 153.570007 1030.930054 20 17-12-08 154.809998 1037.050049 2017-12-11 155.410004 1041.099976 2017-12-12 156.740005 1040.479980 2017-12 -13 153.910004 1040.609985 2017-12-15 152.500000 1064.189941"""
[Python] Plotting multiple stocks