0

I have a function that gives an output of 100+ elements for each input, and each output is appended to a list creating a list of lists:

def func(mols: List[str]):
    feaut = []
    for i, mol in enumerate(mols):
        feaut.append(FG.features_generator(mol)) #This is calling another function from a 
     return feaut                                # package I am using 
   

This is the output:

  [[2.1874960973678963,10.264662506490405,2.7071067811865475,1.9855985596534889,...],
   [2.475534205527556,24.264662506490403,2.7071067811865475,1.9472135954999579,...]]

What is required is to create a DataFrame that has the element passed into the function in one column and each element of the output in separate columns, like the following:

element passed output1 output2 output3 outputN
one 2.187 10.264 2.707 1.985
two 2.475 24.26 2.70 1.94

What I currently have is:

element passed output
one [2.187,10.264,2.707,1.985...]
two [2.475,24.26,2.70,1.94... ]
  • Instead of a list make feaut a dictionary using i for the keys and whatever is returned by FG.features_generator for the values. – norie Aug 01 '21 at 17:25
  • @norie The problem is that the values are stored as a list of size 100, what I need is to divide up that list into separate columns. – user16470918 Aug 01 '21 at 18:19
  • 1
    If you created a dictionary as I suggested you could then use pandas `DataFrame.from_dict` with the orient argument set to `index` to get the data in the format you want. I'd post the code but the question has been closed. – norie Aug 01 '21 at 18:22
  • create a `index = []` then `index.append(mol)` then just use `pd.DataFrame(feaut, index=index)` – juanpa.arrivillaga Aug 01 '21 at 18:41

0 Answers0