0
votes

I have multiple dataframes df1, df2, df3 etc.,

The dataframes have no relationships with each other. Therefore, I am not looking to Append/Join/Merge them and put them as a single dataframe inside a dictionary.

I want to create a dictionary that encloses these dataframes.

dfs = {}

I want to add my df1, df2, df3 inside my dfs.

So that when I need that dataframe I can use something like dfs[df1] to call it back. How Can I do this in Pandas.

1
{'df'+str(e+1):i for e,i in enumerate(df_list)} ? - anky
@anky_91 sneaking in with the better answer once again ;) - rahlf23
@rahlf23 I need yours. I don't have df1, df2 in real scenario. the key value pair sort of thing might suit me more. Can you please give yours as an answer. I can mark it. Thanks. - Siddharth Thanga Mariappan
@anky_91 maybe dict(enumerate(l)) is good enough :-) - BENY
@Wen-Ben Nice one, how do we zip a custom name eg df here? just asking for future ref. :) - anky

1 Answers

4
votes

If your question is suited towards a key-value pair scenario then it may be conducive to store them as such:

dfs = {'df1': df_one, 'df2': df_two, 'df3': df_three}

Otherwise, I would recommend the answer given by @anky_91:

dfs = {'df'+str(idx+1): i for idx, i in enumerate(df_list)}