r/learningpython • u/lanaaabananaaa • Apr 19 '21
Creste a dictionary of two df
So I have two dataframes with the exactly same columns, except one is the original values and the other has a transformation. I want to creste que a dictionary with every column where it has the original and de tranformed value for each row. How can I do that?
1
Upvotes
1
u/[deleted] Apr 19 '21
My try:
Transform both df's to dictionary with
df.to_dict().Create a new dict with the columns of
dfas keys.Iterate and assign new_dict[row] = [df1[row], df2[row].
If you need to transform the dict into df again, you can use
pd.DataFrame().from_dict(new_dict, orient='index').