My data are in a data frame. It looks like this.
I am trying to convert the data frame into the following format:
Currently I'm doing this conversion using the following Python codes, which are tedious.
def f(row):
if row['d1'] == 1:
return 1
if row['d1'] == 2:
return ''
if row['d1'] == 3:
return ''
if row['d1'] == 4:
return ''
else:
return ''
return np.nan
df['t1']=df.apply(f, axis=1)
Any help would be greatly appreciated.

