I have a list of objects that I would like to check and extend. Specifically, my initial dataframe is
Name
1 object1
7 object2
6 object3
4 object4
0 object5
8 object6
I apply the following function to my dataframe:
def example(file):
...
my_list2 = []
for u in file['Name']:
try:
minim = ...
except:
minim = 'NA'
my_list2.append(minim)
file['Others'] = my_list2
return file
to create a new column, Others, that looks like:
Name Others
1 object1 [object4, object3, object22]
7 object2 [object1]
6 object3 [object1]
...
What I would like to do is to apply the function also to each element in the lists in Others column. This means that I should run it for each variable in the first list, i.e.,
[object4, object3, object22]
in order to add to my initial dataframe one row (object22, since it is not included in Name column) and have something like this
Name Others
1 object1 [object4, object3, object22]
7 object2 [object1]
6 object3 [object1]
...
10 object22 [object23, object40, object1]
Of course, the loop stops to run when all the elements in Others are in the Name column.
objectX is just a dummy name for this example: the name of variables in Name could be dog, or mom, or whatever else.
I do not know how to run the function in order to apply it to the elements in the lists under the Others column, to append the results in the original dataset.
Please let me know if you need more information.
Summary:
I need to run the function
- for the objects in the column name. This generates a list of strings per each object (eventually, empty lists too);
- for each object in the list of strings: this creates new rows in Name column
- for the new objects added in the
Namecolumn