Scenario: I have a function that calls an API and retrieves data. The input of this function is a Year.
Objective: I have a list of years and want to call the function sequentially in a loop, and add the results to either:
- multiple Dataframes (changing the names as it loops)
- or append to a single Dataframe as new dimensions.
Issue: For multiple dataframes, I am trying to run a loop, where each iteration creates a new dataframe, and names it based on the year:
for b_years in base_years:
if b_years != '' and b_years >= 2017:
output_df_ + b_years = pd.DataFrame(getAPICore(b_years))
Obs. base_years is a DF with the unique list of years.
Error: For the above snippet, the first part of the third line gives an operator assignment error.
Question 1: How can this operation be performed?
Question 2: If instead of multiple dataframes, I appended every new function result as a new dimension of a single dataframe:
for b_years in base_years:
if b_years != '' and b_years >= 2017:
outputdf_name = pd.DataFrame.append(getAPICore(b_years))
the function ends with no error/result. Is there a way to do this operation?