How to create asymmetrical data set with pandas?

Viewed 82

Context

I'm acquiring (x, y, z) from pictures. I have script that returns 21 points in form of:

0 x0 y0 z0
1 x1 y1 z1
...
20 x20 y20 z20

from one pictue.

I'm trying to write function so I could pass image set and it would create .csv like that:

0 x1_0 y1_0 z1_0       x2_0 y2_0 z2_0
1 x1_1 y1_1 z1_1       x2_1 y2_1 z2_1
...
20 x1_20 y1_20 z1_20   x2_20 y2_20 z2_20

for many images.

I want it to work for many image sets so it could give me file like that:

0 x1_0 y1_0 z1_0       x2_0 y2_0 z2_0
1 x1_1 y1_1 z1_1       x2_1 y2_1 z2_1
...
20 x1_20 y1_20 z1_20   x2_20 y2_20 z2_20

0 x1_0 y1_0 z1_0       x2_0 y2_0 z2_0
1 x1_1 y1_1 z1_1       x2_1 y2_1 z2_1
...
20 x1_20 y1_20 z1_20   x2_20 y2_20 z2_20

Issue

Getting to this point is not a problem as long as image sets are the same size. Problem occurs when I want to put there image set with size of 1 and then I put image set of size 2 so the file looks like this:

0 x1_0 y1_0 z1_0       
1 x1_1 y1_1 z1_1       
...
20 x1_20 y1_20 z1_20   

0 x1_0 y1_0 z1_0       x2_0 y2_0 z2_0
1 x1_1 y1_1 z1_1       x2_1 y2_1 z2_1
...
20 x1_20 y1_20 z1_20   x2_20 y2_20 z2_20

and I want to pd.read_csv() with such asymmetrical data. I get error:

pandas.errors.ParserError: Error tokenizing data. C error: Expected 4 fields in line 45, saw 7

Is there a way to deal with this?

My goal is to be able to put points from image set of different sizes into an existing file.

0 Answers
Related