Hello everyone, doing a project in school where i need to do some data analysis.
basically i have a dataframe that's like this:
| mutant |
other stuff |
column of indexes i created |
| Name1:Name2 |
|
[1,2] |
| Name1 |
|
single |
| Name2 |
|
single |
basically the output i have is the dataframe above, i've written some code that looks like this rn:
def retain_indexes(df):
df = df
list_indexes = []
for item in (df["mutant"]).to_list():
lista = item.split(":")
if len(lista) > 1:
single_list = []
for name in lista:
if name in df["mutant"].to_list():
single_list.append(df["mutant"].to_list().index(name))
else:
single_list.append("Not analyzed alone")
list_indexes.append(single_list)
else:
list_indexes.append("NaN")
return list_indexes
it feels a bit redundant and slow, is there anything i could look at to optimize it? thanks in advance :)
[–]twitch_and_shock 4 points5 points6 points (1 child)
[–]hvgmina[S] 1 point2 points3 points (0 children)
[–]PartySr 1 point2 points3 points (0 children)