Reputation: 3490
I have a dataframe df['type']
where I want to randomly assign one of the two string values: hello, bye to all rows in this column. How can I do so?
Upvotes: 1
Views: 154
Reputation: 863701
Use numpy.random.choice
with length of DataFrame
:
df['type'] = np.random.choice(['hello','bye'], size=len(df))
For boolean:
df['type'] = np.random.choice([True, False], size=len(df))
Or:
df['type'] = np.random.choice([1, 0], size=len(df), dtype=bool)
Upvotes: 2