import re
text = """;500;616;;”YPO_INV”;”KP”;”51D0072”;”YNU”
;” 6,291.00”;;
;500;6900;;”YPNV”;”KE”;”53213072”;”YOU”
;” 6,991.00”;;"""
r = re.compile(r'\n^(?!;500)', re.M)
text = r.sub(';', text)
print(text)
aW1wb3J0IHJlCgp0ZXh0ID0gIiIiOzUwMDs2MTY7O+KAnVlQT19JTlbigJ074oCdS1DigJ074oCdNTFEMDA3MuKAnTvigJ1ZTlXigJ0KO+KAnSAgICAgNiwyOTEuMDDigJ07Owo7NTAwOzY5MDA7O+KAnVlQTlbigJ074oCdS0XigJ074oCdNTMyMTMwNzLigJ074oCdWU9V4oCdCjvigJ0gICAgIDYsOTkxLjAw4oCdOzsiIiIKCnIgPSByZS5jb21waWxlKHInXG5eKD8hOzUwMCknLCByZS5NKQp0ZXh0ID0gci5zdWIoJzsnLCB0ZXh0KQoKcHJpbnQodGV4dCk=