samedi 26 août 2017

Creating random samples with same number of instances for each element

In one part of my project , I need to create a random month-names and store them into a data-frame column. currently I am using the following snippet: First, Creating a data-frame of predefined size:

df = pd.DataFrame(index=range(size))

then creating 120 random Time-Stamp and storing them into ['Timestamp'] column:

df["Timestamp"] = [ pd.Timestamp(2017, np.random.randint(1,13), 1) for _ in range(120) ] 

at the end extracting the Months and stroing them into ['STD_Months'] column :

df["STD_Months"] = df["Timestamp"].apply(lambda x: x.strftime('%B'))

this creates random months but with different quantity , I mean we may have 10 January out of 120 samples , 14 May , 8 December etc(Not equal quantity)

How can I modify my code to have the same quantity of random samples(10 instances of each month name:10 January , 10 February , .... ,10 December)




Aucun commentaire:

Enregistrer un commentaire