I'm working with a stored procedure in which I pass it a start and end date and it returns data. Im passing it ten different dates and making ten calls to it, see below:
match1 = sp_data(startDate = listOfDates[0], endDate=listOfDates[0])
match2 = sp_data(startDate = listOfDates[1], endDate=listOfDates[1])
match3 = sp_data(startDate = listOfDates[2], endDate=listOfDates[2])
match4 = sp_data(startDate = listOfDates[3], endDate=listOfDates[3])
match5 = sp_data(startDate = listOfDates[4], endDate=listOfDates[4])
match6 = sp_data(startDate = listOfDates[5], endDate=listOfDates[5])
match7 = sp_data(startDate = listOfDates[6], endDate=listOfDates[6])
match8 = sp_data(startDate = listOfDates[7], endDate=listOfDates[7])
match9 = sp_data(startDate = listOfDates[8], endDate=listOfDates[8])
match10 = sp_data(startDate = listOfDates[9], endDate=listOfDates[9])
See listOfDates
pandas series below:
print(listOfDates)
0 20220524
1 20220613
2 20220705
3 20220713
4 20220720
5 20220805
6 20220903
7 20220907
8 20220928
9 20221024
Name: TradeDate, dtype: object
Is there a better and more efficient way of doing this? Potentially in a loop of some kind?
Any help greatly appreciated, thanks!
CodePudding user response:
You could use a list comprehension to make a list of matches:
matches = [sp_data(startDate=trade_date, endDate=trade_date) for trade_date in listOfDates]