List index out of range when turning CSV into dict - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: List index out of range when turning CSV into dict (/thread-33603.html) Pages:
1
2
|
RE: List index out of range when turning CSV into dict - ranbarr - May-11-2021 (May-10-2021, 07:25 PM)perfringo Wrote:(May-10-2021, 06:36 PM)ranbarr Wrote: It's an Excel but I saved it as CSV Its saved as CSV (comma delimited), not UTF - 8 RE: List index out of range when turning CSV into dict - ibreeden - May-11-2021 @ranbarr: About your code: although there is room for improvement your code should work. The problem is in the data. About saving your data as CSV: I don't have Excel so I cannot check, but when saving your data as CSV, is there an option to choose a separator? It seems a space is chosen as separator. If there is no option to choose a separator, please read How to change the delimiter when exporting CSV from Excel. RE: List index out of range when turning CSV into dict - ranbarr - May-11-2021 (May-11-2021, 08:24 AM)ibreeden Wrote: Excel so I cannoI tried to save the file as CSV UTF and just as CSV after changing the delimeter and list seperation as the guide said.. still getting the same output
RE: List index out of range when turning CSV into dict - perfringo - May-11-2021 (May-11-2021, 07:52 AM)ranbarr Wrote:(May-10-2021, 07:25 PM)perfringo Wrote: My up-to-date Excel under macOS has this exact option to save as csv. There are other options as well ( Comma Separated Values (.csv) , Macintosh Comma Separated (.csv) , MS-DOS Comma Separated (.csv) ) but this one should be preferred as 'universal encoding'. However, regardless of saved encoding separator must be present anyway.For those of us who use Mac and have ; as separator:Quote:For Mac OS the chosen value separator depends on Region and region's default number separators. To change them, go to “System Preferences” > “Language & Region”. Then you need to verify the number separators in “Advanced …” > “General”. RE: List index out of range when turning CSV into dict - ibreeden - May-11-2021 (May-11-2021, 09:23 AM)ranbarr Wrote: I tried to save the file as CSV UTF and just as CSV after changing the delimeter and list seperation as the guide said.. still getting the same output Not so hasty, programming is a matter of stepwise refinement . First look at the CSV file. Use NOTEPAD.EXE or vi to inspect it. Does it contain separators as it should? Second: ajust your code to match the field separator and show us your code. And then also show the output. The complete output, not the line ending with a comma as you did. And if there are errors we want to see the complete error message. RE: List index out of range when turning CSV into dict - ranbarr - May-12-2021 (May-11-2021, 12:57 PM)ibreeden Wrote:(May-11-2021, 09:23 AM)ranbarr Wrote: I tried to save the file as CSV UTF and just as CSV after changing the delimeter and list seperation as the guide said.. still getting the same output Yeah hasty is indeed my problem lol... I did all this and changed the code and it worked! TY! |