Csv file different delims

Greetings!

I need help cleaning a csv file. It has 6 columns of floats. The problem: If the next float in a row has a minus sign, the delimiter between the two floats is 3 spaces. If the next number is positive (no sign), the delimiter is 4 spaces. I have no idea how to read this file properly into a Python object (array, data frame tensor?). Or how to rewrite the file first with consistent delimiters as the read functions already ask for delimiters…

Any help?

PiF

EDIT: I just solved this problem using the Linux shell program vim. To replace a single string with another string is a single command there. Wonder whether Python would be as easy as well.

Good to hear you’ve solved the issue. I think pandas is a great tool to clean and read data frames, so it could be useful in the future.

1 Like