0

i am new to python, trying to parse a csv. Made some bounding boxes for MNIST. Now i want to convert the csv to xmls to train a yolo detector.

But i came along a pretty strange thing: (python keywords^^)

These are my rows, got thousends of them, 10 to one image:

filename    mnist_images_300_300_bigger_all/mnist_1.jpg
width                                               300
height                                              300
class                                                 7
xmin                                                  0
ymin                                                  0
xmax                                                 42
ymax                                                 42
Name: 0, dtype: object
Path were to write xml:  Bilder_LabelXML/mnist_images_300_300_bigger_all/mnist_1.xml
Path were image from:    mnist_images_300_300_bigger_all/mnist_1.jpg

If i want to access them now, i wrote in my script:

for index, row in group.object.iterrows():
    print(row.class)

Which gave me that error:

File "annotations_CSV_to_XML.py", line 81
    ET.SubElement(size, "name").text = row.class
                                           ^
SyntaxError: invalid syntax

If i access ymax, everything is fine:

for index, row in group.object.iterrows():
    print(row.ymin)

How can i delimit or mask the keyword "class", that python understands it and does not thing i want to create a new class?

Thanks in advance..

4
  • 1
    See stackoverflow.com/q/44859431/476 Commented Dec 17, 2019 at 11:16
  • solved it by using row[3] instead of row.class Commented Dec 17, 2019 at 14:16
  • 1
    Or consider row['class']. Commented Dec 18, 2019 at 13:29
  • okay thought i had tried it, but obviously not, it works with row['class']... thx alot Commented Dec 18, 2019 at 14:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.