Reputation: 3450
I want to assign random numerical values ranging from 600-1200 to my column df['size']
but based on another column. So if the value of the same row in df['type']
is yes, the value of df['size']
should be in a range from 600-1200 but if the value of df['type']
is "no", then the value of df['size']
should be a random value between 1500-2000.
df['size'] = np.random.randint(600,1200, size=len(df))
Upvotes: 0
Views: 43
Reputation: 862406
Use numpy.where
for select if matched yes
or not:
a = np.random.randint(600,1200, size=len(df))
b = np.random.randint(1500,2000, size=len(df))
df['size'] = np.where(df['type'].eq('yes'), a, b)
Upvotes: 2