I am very very new to python so apologies in advance, i have been trying to solve this for hours.
I have a set of data like this, but much much larger:
A B C D
1 23 16 NaN 14
2 26 17 23 23
3 23 NaN 22 25
4 24 34 28 28
I need to make another column (E) that takes the average score of specific columns, such as B,C and D, for that particular row.
If across this row, there are any missing values (NaN) then i need "missing data" to be shown in row E in place of where the mean score would be.
I have tried changing the NaN outputs to 0s (which was successful) and then running something similar to the following (my code has become a complete mess and i have forgotten where i started or what i have tried):
composite = []
for df in column ["A","B","C"]:
if value > 0:
composite.append(df[:, ["A","B","C"]].mean(axis=1))
else:
composite.append("missing value(s)")
df["composite"] = composite
print(df)
I know that this code here probably has lots of errors but its a rough structure of what i am trying to do.
I have also tried every method i could find on google, including other techniques such as .loc functions. I did not want to have to ask for help as usually i'm confident i can find the solution on my own using previously posted questions, but in this instance i haven't been able to make anything work despite spending hours combing through google.
Any help would really be appreciated. I have also been told that i HAVE to use a for loop. Additionally, if this can be done without changing the NaN values to 0 this would be preferable.
Thank you for any input.