I want to generate 6 random numbers(weights) that always equals one 1000000 times and multiply it the columns of a data i have imported from as csv file. Store the sum in another column(weighted average) and find the difference between the max and min the new column(range). I want to repeat the process 1000000 times and get the least range and the set of random numbers(weights) generated to find that.
Here is what i have done so far: 1.Generate 6 random numbers 2.Import data from csv 3. Multiply the data random numbers with the data from the csv file and find the average(weighted average) 4. save the weighted average in a new column F(x) 5. Find the range 6. Repeat this 1000000 times and get the random numbers that gives me the least range.
Here is some Data from the file
     A    B      C    D      E    F    F(x)
 0  4.9  3.9    6.3  3.4    7.3  3.4    0.0
 1  4.1  3.7    7.7  2.8    5.5  3.9    0.0
 2  6.0  6.0    4.0  3.1    3.7  4.3    0.0
 3  5.6  6.3    6.6  4.6    8.3  4.6    0.0
Currently getting 0.0 for all F(x) which should not be so.
arr = np.array(np.random.dirichlet(np.ones(6), size=1))
arr=pd.DataFrame(arr)
ar=(arr.iloc[0])
df = pd.read_csv('weit.csv')
df['F(x)']=df.mul(ar).sum(1)
df
df['F(x)'].max() - df['F(x)'].min()
I am getting 0 for all my weighted averages. I need to get the weighted average
I cant loop the code to run 1000000 times and get me the least range.