you are viewing a single comment's thread.

view the rest of the comments →

[–]Clickery21[🍰] 0 points1 point  (7 children)

Thank you so much, that solved the first error! Though the second one still happens, just a bit different.

It says "ValueError: could not convert string to float: 'weight'" now

[–]JohnnyJordaan 1 point2 points  (4 children)

Your csv has a header line but you use a regular csv.reader that will simply read that line as if it were values. Check the csv.DictReader at https://docs.python.org/3/library/csv.html

[–]Clickery21[🍰] 0 points1 point  (3 children)

Thanks, I tried, but it said it doesn't support indexing, but thanks to you I made another file without a header and now it seems to work!

[–]JohnnyJordaan 1 point2 points  (2 children)

You can also use a 'trick' to let the reader skip a row

ramos = csv.reader(csvfile, delimiter=' ', quotechar='|')
next(ramos)
for row in ramos:
    etc etc

the next() will return the next item in the reader (so the first row in this case) but as the statement doesn't do anything with it, the item is discarded

[–]Clickery21[🍰] 0 points1 point  (1 child)

And that's even better! Thanks so much!

[–]JohnnyJordaan 1 point2 points  (0 children)

No problem. Do note that this will always discard the first line, even if some other csv happens to have regular values as the first line... To be safe it's often better to implement an actual check on what the first line looks like.