What am trying to do is in each task I have elements and am going to randomly choose an element and create a matrix the same size as the data and put 1 for the selected element and 0 for the non-selected one
The issues I have faced are that my data is not equal in length so that posed as a problem when I used pandas dataframe so I made it equal but another problem arose mentioned below
If you can help me solve the issues or suggest a better way to do this other than what I tried
here is when I tried list of lists but I couldn't find the index to add the 1s to the matrix
and this is when I tried pandas dataframe and I couldn't select randomly from a column
The issues I have faced are that my data is not equal in length so that posed as a problem when I used pandas dataframe so I made it equal but another problem arose mentioned below
If you can help me solve the issues or suggest a better way to do this other than what I tried
here is when I tried list of lists but I couldn't find the index to add the 1s to the matrix
Python:
import random, numpy as np
l=[[[10,20],[2,3]],
[[5,2]],
[[10,55],[2,0],[12,0]]]
ln=len(l)
n=int(0)
if n<ln:
for k in l:
print(random.choice(l[n]))
n+=1
m=max(len(x) for x in l)
zeroarr = np.zeros((ln,m),dtype=int)
and this is when I tried pandas dataframe and I couldn't select randomly from a column
Python:
import pandas as pd, random, numpy as np
task1 = [[2,3],[6,5],[0,9]]
task2 = [[10,7],[6,2],[2,1]]
task3 = [[3,8],[6,7],[4,3]]
data=pd.DataFrame({'t1':task1,'t2':task2,'t3':task3})
zeroar=np.zeros(data.shape,dtype=int)
zeroar