What is the best way to transform the below input into look like the output for a large data set using dataframe?
INPUT