uneven number of data points on each trial_data collection

I have a task where peole see a dot moving and then disappearing. When that happens they need to indicate with the mouse where it started and where it vanished. The motion trajectory can be 1 line, 2 lines, or 3 lines.
The data I collect is the actual initial position of the dot (in both axes), the actual vanishing position (both axes), the trial number, the condition, the perceived position of the dot (start, vanish both axes), the direction of the first line, and if there is a 2nd line the direction of it.
Because there are uneven data points, my values are not correctly placed under the right header at the csv file that I “send” the data to.
I would appriciate it if anyone could help with making the headers align with the data.

I tried to create a loop when I push the headers. It works for the 3 lines trajectory but not with the others.