So I got a folder with a bunch of CSVs and inside these csvs there are simple tables sep=';', the problem comes when in one column of these tables, which contains text, there are lines that start with \n and of course, these rows don't have the same length as the others, because the \n breaks the line. What I'm trying to do is to add the lines that startwith('\n') to the previous line. I'll leave the code below, it doesn't get me an error, but it doesn't solve the problem either. I'm pretty sure there are simpler ways to do these but I not getting the inspiration. =)
with open(path_csvs, 'r',encoding='latin-1') as f:
lineas = f.readlines()
with open(path_csvs, 'w',encoding='latin-1') as f:
i = 0
while i < len(lineas):
if i < len(lineas)-1 and lineas[i].startswith('\n'):
f.write(lineas[i].rstrip() + ' ' + lineas[i-1].lstrip())
i += 2
else:
f.write(lineas[i])
i += 1