I have a dataframe containing 43 columns and i want to iterate only over 3 columns (C, D, E) if value in column A is 1,5. Those 3 columns contain either really complex sentences or NaN. I want to append value 1 to NEW column to those rows, that only contain NaN in all 3 columns while i want to append value 0 to those rows, if either of columns contain sentence.
Dataframe looks like this:
df
A B C D E
1.5 x grass is green NaN NaN
1 y NaN ball is red NaN
1.5 z NaN NaN NaN
I suppose the beggining of the code should look something like this:
for rating in df['A']:
if rating == 1.5:
for index, row in df.iterrows():
print (row["C"], row["D"], row["E"]
What would be a possible solution to get result looking like this:
df
A B C D E NEW column
1.5 x grass is green NaN NaN 0
1 y NaN ball is red NaN
1.5 z NaN NaN NaN 1