I've got a CSV file which has a bunch of stock information I need to whittle down to a specific format for another program to read. The first line in the CSV file contains the header, the CSV file contains 29 keys and I need to get down to 11. After that I have to do some tests on one of the keys values, removing the whole row if the test matches. Finally, each remaining row has to be jammed together as a single string with an EOL and output to a file.
This is the order I'm attempting to do things in:
- Read in the CSV file as a dictionary
a. CSV = csv.dictreader(open('sampledata.csv', 'rb') - Remove all the excess keys and their values from the dict
a. del CSVreader doesn't work...? - Perform a test on all the values of one of the keys and removes the entire row if it matches
a. if ExeShare == 0 delete row from dict - Print the leftover rows in a specific ordered format with NO commas
a. Each rows data is joined together as one long string
I'm assuming because the first line contains the header, dictReader will correctly name all the key values, but whenever I try to del a key it throws "DictReader instance has no attribute '__delitem__'"
This is my first time working with the CSV module and I can't get past step 2, so any and all help would be most appreciated!