Assume a DataFrame
C1 C2 C3
1 NaN NaN NaN
2 20.1 15 200
3 NaN 12 100
4 22.5 8 80
I want to create a new column based on a summarizing boolean of the rest of the row. For example, are any of the values NaN? In that case, my new column value would be "False" for that row.
Or, perhaps, are ALL of the values NaN? In that case, I might want the new column to say False but otherwise True (we do have some values)
I considered using df.notnan()
to create a Boolean DataFrame,
C1 C2 C3
1 False False False
2 True True True
3 False True True
4 True True True
I'm sure I'm just missing something simple, but I could not come up with a way to create the fourth column based on OR-ing the existing items in each row.
Also, a generic solution would be nice, one that doesn't require building an interim DF of Booleans.
Background: I have a dataset. Nutrient values are only sampled occasionally, so many of the rows do not contain those values. I would like to have a "Nutrients Sampled" column where the value is True or False based on whether I can expect to see any nutrient sample data in this record. There are 6 possible nutrients and I don't want to check all 6 columns.
I can write the code that checks all 6 columns; I just can't seem to create a new column with a truth value.