How do I generate random numbers in a specific range which is correlated to other column values?
I have a data frame with the column, let's say, height
and I need to generate an extra column with a diameter within a range, AND the diameter should strongly correlate to the height? How to do this?
What I have done here is generate random height values in the range, different for each species. However, I could not find a solution for generating diameter values in a new column, in a specific range.
I would need the diameter to be between values 30 and 70
for 'pinus_mugo'
and between values 50 and 100
for 'pinus_nigra'
.
import numpy as np
import pandas as pd
points.loc[points['species']== 'pinus_mugo', 'height'] = \
np.round(np.random.uniform(35.0, 59.0,
size=(len(points[points['species']== 'pinus_mugo']), 1)), 2)
points.loc[points['species']== 'pinus_nigra', 'height'] = \
np.round(np.random.uniform(20.0, 43.0,
size=(len(points[points['species']== 'pinus_nigra']), 1)), 2)