I have data as shown in the picture, please check the dataframe here:

I want to convert that data amsterdam_01136.txt, amsterdam_01239.txt ... so on
which should look like this (yolo object detection annotation format)
0 0.982552 0.597656 0.034896 0.121094
0 0.742448 0.613770 0.028646 0.059570
2 0.418750 0.540527 0.038542 0.200195
I tried using for loop as given here (3rd solution) link but it only adds the last row of the file name. please give me a suggestion