@Sahithi_7,
please use proper markdown code tags when providing code/data samples. The markdown code tags are reference in the forum welcome page here.
I don't think we're getting any traction withOUT any specific simple, representative and reproducible input data samples (if there're multiple) AND the corresponding desired output example.
So far we have lots of "hand waving" and sprinkles of the unformatted inputs.
I don't think we'll get anywhere with this thread unless/until you provide all the requested and properly formatted data.
Also, we'd ask you to provide your own attempt(s) at solving this issue - this will enable us to help you in any tangible way.
Let's see how far you get with the above.