Hey guys, i have a problem with reading csv files. I have a csv file which i would like to read and save to a dictionary.
Preview of the file:
mpg;engine;horse;weight;accel;year;origin;cylinder
18;307;130;3504;12;70;1;8
15;350;165;3693;11,5;70;1;8
18;318;150;3436;11;70;1;8
16;304;150;3433;12;70;1;8
and so on..
The way that i would like it to save is basically for example mpg is the key, while 18,15,18,16.. are the items. (ex. mpg:18,15,17...)
I have tried to do it with and without the csv class, but i still can't make it to save the variable as a key into a dictionary. I've managed to save the entire csv file to an array, but it isn't what im after and therefore i can't post any code that would help.

Thanks in advance for all the help.

Regards

Recommended Answers

All 3 Replies

I tried all of the sample code given on that link, but only one was a match to what i was searching, but it was a bit overcomplicated with that extra class in it (amateur in python), so im still looking for a bit more simple code..

How about my named tuple code in code snippets?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.