mercredi 20 mars 2019

Reading in excel file into pandas depending of the month

Hi,

I'm trying to read in a excel file into pandas.

I am using the following code to get the previous month:

today = datetime.date.today() 
first = today.replace(day=1) 
lastMonth = first - datetime.timedelta(days=1)

Then I go to pull in the file without any errors:

if lastMonth == 12 : pods = pd.ExcelFile(r'\\somedrive\PODS data - PODS data - Jan 19.xlsx')
elif lastMonth == 1 : pods = pd.ExcelFile(r'\\somedrive\PODS data - Feb 19.xlsx')
else lastMonth == 2 : pods = pd.ExcelFile(r'\\somedrive\PODS data - Mar 19.xlsx')

I then attempt to see if it was successfully pulled in by typing pods and I get the following error:

NameError Traceback (most recent call last) in ----> 1 pods

NameError: name 'pods' is not defined

I'm sure it is something simple, but I can't quite figure out what it is

Aucun commentaire:

Enregistrer un commentaire