Issue
I guess this code can write in for loop, but I have no idea how to do it? Thanks a lot!
worksheet1=pd.read_excel(xls,"sheet2",usecols=feature1)
worksheet2=pd.read_excel(xls,"sheet2",usecols=feature2)
worksheet3=pd.read_excel(xls,"sheet2",usecols=feature3)
worksheet4=pd.read_excel(xls,"sheet2",usecols=feature4)
worksheet5=pd.read_excel(xls,"sheet2",usecols=feature5)
worksheet6=pd.read_excel(xls,"sheet2",usecols=feature6)
Solution
Try
featuresList = [feature1,feature2,feature3,feature4,feature5,feature6]
worksheets = [pd.read_excel(xls,"sheet2",usecols=feat) for feat in featureList]
then you can call to worksheets[1]
wich is worksheet2 and so (one index displacement)
EDIT
As suggested, A list comprehension is a way to compress an for sentence in one line, it's general form is:
result_list = [do_something for val in iterator]
It return a list doing some work over an iterator
Answered By - Ulises Bussi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.