I am trying to create a DataFrame based on the values of two columns of another 2 DataFrames.
I want the new DataFrame to be the share of the value of one of the columns (b) between all the values on the other column (a) based on their weighted contribution to that column (a).
At the moment I have been able to solve it with a loop. But I was wondering If you can think of any vectorized function from pandas that could solve this quicker?
a = pd.DataFrame(np.random.randint(1, 6, 700))
b = pd.DataFrame(np.random.randint(1, 6, 400))*1000
final_share = []
weight = a/a.sum()
for index, value in b.iterrows():
weighted_value = weight*b.iloc[index].item()
final_share.append(weighted_value)
final_share = pd.concat(final_share, axis = 1)
final_share.columns = b.index