vendredi 20 mai 2022

Random subsetting a data frame from a larger dataframe

n=100 (n=height * width) height=10 width=10 column = [1,2,3,4,5,6,7,8,9,10]
indices = [1,2,3,4,5,6,7,8,9,10]

Rack2 = pd.DataFrame(np.random.choice(np.arange(n),size=(height, width), replace=False), index=list(indices), columns=list(column))
Rack = Rack2.sort_index(ascending=False)
a = np.repeat([True,False], Rack.size//2) 
b = np.random.shuffle(a)
a = a.reshape(Rack.shape)

SI = Rack.mask(a)
RI = Rack.where(a)

StorageSet = SI.stack() 
ss=dfStorage.index

RetrievalSet = RI.stack() 
tt=D3.index

In the python code above, there is a 10x10 Rack. Half of the rack (50 items) consists of storage items and the other half consists of retrieval items. I want to do it not half of the rack size but if I have a 10x10 rack for example 30 of that data frame are storage items. 30 of the remaining 70 items are the retrieval items. How can I do this?




Aucun commentaire:

Enregistrer un commentaire