-1

Is there anyway I can update remaining data frames in a dictionary after I update the first one?

For context I have multiple df in a dictionary and I'm running them one by one. I run them one by one using this pseudo code/process:

i = 1
y= 2

# Run an algorithm on the first df in the dictionary
output= dic[i].sort_values(by = ['TEAM', 'GROUP','SCORE'], 
                          ascending = [False,False,True],  ignore_index=True)
output= output['SCORE'] - 1


# Update the SCORE of the remaining dfs in the dictionary where GROUP is the same
#This code only updates the next df in the dictionary

dic[y] = dic[y].join(output.drop(columns=(['TEAM'])).set_index(['GROUP']), 
             on=['GROUP'], rsuffix='_NEW')

dic[y].loc[dic[y].SCORE_NEW.notna(), 'SCORE'] = dic[y].SCORE_NEW
dic[y] = dic[y].drop(columns='SCORE_NEW')

i+=1
y+=1

Any way that I can update all the remaining dfs on that dictionary instead of just the next one?

its.kcl
  • 111
  • 6
  • It's not entirely clear what you're asking for. If you want to operate on multiple items in a collection at the same time, you would need some sort of [multiprocessing](https://docs.python.org/3/library/multiprocessing.html) – G. Anderson Jun 03 '22 at 17:47
  • 1
    You probably don't need multiple entries in the dic. This looks like an XY problem. Here you ask how to split a group by : https://stackoverflow.com/questions/72491840/how-can-i-subset-dataframe-and-put-them-on-a-list . You probably just need ONE dataframe, and use `groupby` accordingly. Why dont you make a post explaining your actual problem, instead of posting repeated small workarounds to smaller problems? :) This will definitely help us give you a more broad answer. – rafaelc Jun 03 '22 at 17:52
  • I'm just trying to figure out a way to access all the data frames in the dictionary so I can update the other data with their Score, it can be through another inner while loop. – its.kcl Jun 03 '22 at 17:52
  • @rafaelc, sorry! Last time I asked another question in a post I had, they asked me to post a new one so I thought I had to create a new one. – its.kcl Jun 03 '22 at 17:54
  • You can create a new one. My point is: explain your whole problem, not bits of it. Post a [mcve] of your input and your final desired output. – rafaelc Jun 03 '22 at 17:55

0 Answers0