0

I have three lists with angle values:

import pandas as pd
import random

# Example data
angles1 = [1,1,5,6,4]
angles2 = [3,2,5,4,9]
angles3 = [6,9,8,2,1]

The angle values of the three lists are dependant from each other. This is what the correlation coefficients are showing me.

# Calculate the correlation coefficient
angles = list(zip(angles1,angles2,angles3))
anglesData = pd.DataFrame(angles,columns=['angle 1','angle 2','angle 3'])
print(anglesData.corr())

These are the calculated coefficients (result):

          angle 1   angle 2   angle 3
angle 1  1.000000  0.474267 -0.530212
angle 2  0.474267  1.000000 -0.690651
angle 3 -0.530212 -0.690651  1.000000

I want to randomize values for angle1, angle2 and angle 3. I can easily randomize the angle1 value:

# Get a random number from angles1
randomAngle1 = random.choice(angles1)
print(randomAngle1)

The thing is that I can not simply randomize values for angle2 and angle3 as well, as they are dependant from the value of angle1. They are also dependant from each other.

How can I randomize values for angle1, angle2 and angle3, which make sense and without neglecting the correlation?

Any kind of feedback is always appreciated. Thanks.

michael
  • 47
  • 6
  • I think I need to understand how values for angle2 and angle3 depend on angle1 and so on. And how do you think to solve the problem? Perhaps you need to remember the indices in conjunction with the values and identify them after a random choice of value. – inquirer Aug 20 '22 at 07:39
  • Does this answer your question? [Random row selection in Pandas dataframe](https://stackoverflow.com/questions/15923826/random-row-selection-in-pandas-dataframe) – Vladimir Fokow Aug 20 '22 at 14:02

1 Answers1

1

If the angles of your anglesData correspond to each other if they in the same row (and should not be separated), then you can simply select a random row of your dataframe (it will be a new dataframe consisting of only 1 selected row), which you can then convert into a list:

anglesData.sample().to_numpy().flatten().tolist()

You could also shuffle the rows of your dataframe:

anglesData.sample(frac=1)
Vladimir Fokow
  • 3,728
  • 2
  • 5
  • 27