Skip to content
Advertisement

How can I get multiple dataframes returned from a class function?

So I have made a class that takes in a ticker symbol, and it returns a dataframe with all the price information for the dates specified. here is the code below:

JavaScript

now this works perfectly, but ideally id like to pass in a list of symbols and have it return a seperate df for each symbol. so for example,

symbols = ['aapl','googl','msft','tsla']

and id like it to return 4 seperate dfs, each named aapl_df, msft_df etc. is there any way to do this?

ive tried using a for loop like so

JavaScript

but im not sure how to get it to return seperate dfs.

Advertisement

Answer

As I commented, you can also do something like this:

Edit:

I guess you don’t need to __init__ at all

JavaScript

Also, I think your question more about how to access those dfs like you mentioned aapl_df,msft_df...?

You can just do results['aapl'] instead of writing aapl_df – and so on.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement