0

I am using a dictionary to pull data and using a for loop to store iterate through each item and storing it as a unique key:

df_dict = {}

key_name = {"item1": "url",
            "item2": "url",
            "item3": "url"
           }
   
for key,value in key_name.items():
    temp_df = spy.search(str(value), quiet=True)
    df_dict["{0}".format(key)] = spy.pull(temp_df, start=start_date, end=end_date, header='Name', grid=None)

The spy.search and spy.pull are functions related to Seeq Data Labs but I don't believe to be related to the problem.

This creates a dictionary that looks like:

{'item1': [9226 rows x 19 columns],
 'item2': [5 rows x 8 columns],
 'item3': [8300 rows x 33 columns]}

I want to store each key as the name of a new data frame named 'item1' that has all of the values stored as a data frame

Any help would greatly be appreciated! Thank you!

  • are you looking to do `my_dictionary["item1"] = pandas.DataFrame(my_dictionary["item1"])`? – JonSG Mar 03 '23 at 16:00
  • are you looking to create a dynamically named variable, something akin to `item1 = my_dictionary["item1"]`? – JonSG Mar 03 '23 at 16:08
  • @JonSG it would be item1 = my_dictionary['item1'] and my_dictionary['item1] would be a data frame – Timmy Riordan Mar 03 '23 at 17:14
  • Does this answer your question? [How do I create variable variables?](https://stackoverflow.com/questions/1373164/how-do-i-create-variable-variables) – JonSG Mar 03 '23 at 17:17
  • 1
    @JonSG this is going to sounds really dumb but I didn't realize it was in a dataframe already. Thank you for taking time to comment! – Timmy Riordan Mar 03 '23 at 18:58

0 Answers0