How to crate csv file in below manner?

I have this list. it has tuple elements each tuple consists of license plate image name and numeric values present in the license plate.

For ex:
[ (‘1019.jpg’, [0, 0, 0, 1, 5, 6, 2, 8, 3, 8]),
(‘1020.jpg’, [0, 0, 0, 1, 5, 3, 9, 4, 3, 8]),
(‘1021.jpg’, [0, 0, 0, 1, 8, 1, 9, 6, 5, 6])].

1st I need to remove the preceding 3 zeros.
then I have to create a csv file in following manner

img_id 0 1 2 3 4 5 6 7 8 9

img_1019_1 0 1 0 0 0 0 0 0 0 0
img_1019_2 0 0 0 0 0 1 0 0 0 0
img_1019_3 0 0 0 0 0 0 1 0 0 0
img_1019_4 0 0 1 0 0 0 0 0 0 0
img_1019_5 0 0 0 0 0 0 0 0 1 0
img_1019_6 0 0 0 1 0 0 0 0 0 0
img_1019_7 0 0 0 0 0 0 0 0 1 0
img_1020_1
img_1020_2…
like this

I have totally 200 image files and its license plate numbers. I want to create a csv file in above manner. please help me.

What is the rule that tells you, that this is the correct result?

this is the sample submission provided to me in my school.
I have to submit the results in the above manner

The i 0 0 ...0 1 0...0 with the 1 in position j, means that after getting rid of the three zeros, the ith value was j.

for example 1019.jpg has the values 1 5 6 2 8 3 8
so I have to create 7 rows for 1019.jpg with columns 0 to 9.
I have to write this value in binary manner. 1st row will have 1 in column 1. 2nd column have 1 in column 5. other columns will have 0.

can you please elaborate.

Consider this entry: ('1019.jpg', [0, 0, 0, 1, 5, 6, 2, 8, 3, 8]).

You get the list and drop the 3 leading zeros, leaving [1, 5, 6, 2, 8, 3, 8].

For each number in that list, create a list of 10 zeros [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] and then put a one at the given index, giving [0, 1, 0, 0, 0, 0, 0, 0, 0, 0] for the first one, etc, then prepend the ‘img’ entry, and finally write it out to the CSV file.

1 Like

Make a new thread to ask a new question if you get stuck with anything specific.

Otherwise no. It’s your school work. I’ve given you a good hint, you should attempt it yourself now. Any more is asking other people to do your homework for you.

1 Like