In MATLAB, if I write my own function I can pass an array to that function and it automagically just deals with it. I'm trying to do the same thing in Python, the other Data Science language, and it's not dealing with it.
Is there an easy way to do this without having to make loops every time I want to operate on all values in an array? That's a lot more work! It seems like the great minds working in Python would have had something like this need before.
I tried switching the data type to a list() since that's iterable, but that didn't seem to work. I'm still getting an error that basically says it doesn't want an array object.
Here's my code:
import scipy
from collections import deque
import numpy as np
import os
from datetime import date, timedelta
def GetExcelData(filename,rowNum,titleCol):
csv = np.genfromtxt(filename, delimiter= ",")
Dates = deque(csv[rowNum,:])
if titleCol == True:
Dates.popleft()
return list(Dates)
def from_excel_ordinal(ordinal, _epoch=date(1900, 1, 1)):
if ordinal > 59: #the function stops working here when I pass my array
ordinal -= 1 # Excel leap year bug, 1900 is not a leap year!
return _epoch + timedelta(days=ordinal - 1) # epoch is day 1
os.chdir("C:/Users/blahblahblah")
filename = "SamplePandL.csv"
Dates = GetExcelData(filename,1,1)
Dates = from_excel_ordinal(Dates) #this is the call with an issue
print(Dates)