I am new to Python and I wrote a python code to process excel files. Here's my code
files=os.listdir("XXX")
os.chdir("XXX")
def getDF(xl, sh):
print(sh)
test= xl.parse(sh)
test2=test.iloc[:, (list(range(8))+ list(range(8,len(test.columns),5))) + list(range(9,len(test.columns),5))]
num=list((range(1440)))
aCN = [str(x)+'w' for x in num]
bCN = [str(x)+'r' for x in num]
test2.columns=["a", "b", "c", "d", "e", "f", "g" , 'h']+aCN + bCN
return(test2)
def prepareOneFile(path):
fn = path
xl = pd.ExcelFile(fn)
newDF=[getDF(xl, x ) for x in xl.sheet_names]
df = pd.concat(newDF)
print(fn)
return(df)
app_list= [prepareOneFile(x) for x in files]
The code runs very slow, I can I speed it up? Many thanks11