I have to create a result pandas dataframe from a source pandas dataframe having two columns. The result dataframe should have headers of two types, one type should be from the source dataframe derived from one of the column values appending the column header with the values. The other header is taken as it is from the source dataframe with unique values if there are duplicates. The result dataframe cell values should be 1 depending on whether there was a corresponding derived header from the column values or 0 if none.
The dataframes are as below
dfm = pd.DataFrame({'v' : [44,39,39,8,40,8,15,15],'x':[1,1,1,1,2,2,2,2]})
dfm
v x
44 1
39 1
39 1
8 1
40 2
8 2
15 2
15 2
result
x v_8 v_15 v_39 v_40 v_44
1 1 0 1 0 1
2 1 1 0 1 0