I have a dataframe where some of the columns indicate whether or not a set of survey questions was seen. For example:
Q1_Seen Q2_Seen Q3_Seen Q4_Seen
Q1a nan nan nan
nan Q2a nan nan
nan nan Q3d nan
nan Q2c nan nan
I would like to collapse these columns into one column, let's say Q_Seen
, that would take on the form:
Q_Seen
Q1a
Q2a
Q3d
Q2c
Note that each row would be mutually exclusive: if there is a value in one of the columns, all the others would be NaN.
I tried doing this with pd.concat
, but it didn't seem to be producing correct results.
Try this: