Search code examples
pythonnumpyshuffle

Generating M or F for a 100 data point Python


Is there a way of generating a random sample of Male and Female for my dataframe in Python? Doesnt have to be 50:50 but random every time I ran it? Thanks.


Solution

  • Initialise a RNG object and use its choice method:

    from numpy.random import default_rng
    
    rng = default_rng()
    values = rng.choice(['M', 'F'], size=100)