I am trying to read in 12 separate CSV files and would like to use a for loop to do it. For some reason the code doesn't seem to be working:
files = ['Jan2016', 'Feb2016', 'Mar2016', 'Apr2016', 'May2016', 'Jun2016', 'Jul2016', 'Aug2016', 'Sep2016', 'Oct2016', 'Nov2016', 'Dec2016']
for file in files:
file = pd.read_csv("/Volumes/Toshiba/PrescriptionData/Results2/" + i + ".csv")
print(Jan2016)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-49-906109eb8ce9> in <module>()
4 file = pd.read_csv("/Volumes/Toshiba/PrescriptionData/Results2/" + i + ".csv")
5
----> 6 print(Jan2016)
NameError: name 'Jan2016' is not defined
However, when I enter print(file) the code compiles and prints the data from the Dec2016 CSV file (i.e the final value in my 'files' list). Any ideas on why this for loop is not working?