I have created a dictionary of dataframes to store my data. I need to do some stuff to each dataframe for which I'm trying to use iteritems() to iterate through the dictionary. But somehow i seem to be unable to actually do anything to the dataframes. Code compiles and does not throw any errors, it just seems to not do anything.
Here a simplification of my code:
This just makes a sample dictionary of dataframes
dic={}
df1=pd.DataFrame(np.random.randn(10,5),columns=['a','b','c','d','e'])
df2=pd.DataFrame(np.random.randn(10,5),columns=['a','b','c','d','e'])
df3=pd.DataFrame(np.random.randn(10,5),columns=['a','b','c','d','e'])
df4=pd.DataFrame(np.random.randn(10,5),columns=['a','b','c','d','e'])
df5=pd.DataFrame(np.random.randn(10,5),columns=['a','b','c','d','e'])
dic[1]=df1
dic[2]=df2
dic[3]=df3
dic[4]=df4
dic[5]=df5
And this is a basic set of things i want to do to each dataframe.
for key, item in dic.iteritems():
item=item.reset_index()
item['Rank']=(item.index)+1
So, after the iteration I am expecting each dataframe to have an extra column with the old index, and another extra column with the "Rank" like so:
Instead the dataframe seems to be unaffected by the operations and looks the same as before:
I have tried also to use a temporary dataframe inside the iteration and then try to write it into "item" with the same result. I am just wondering if what i want to do is even possible or maybe i have to go around it and use a different method to achieve my goals.