I have a .csv file that has this structure:
X310.433,Y9.6
X310.54,Y10
X143.52
X144.77
when there is no "X" or "Y" value in a line, I want to take the value from the line above and copy it to the line after that, that is missing the value. For this example copy the Y10 into the next line, and seperate it with a comma. How can i do this with python?
Without any utility modules you could do this:
Let's assume that the file content is:
...then...
Output:
Note:
If the first line of the file contains either one of X or Y (but not both) this will fail
EDIT:
More robust version that rewrites the original file: