On Thu, May 10, 2012 at 5:05 PM, Prasad, Ramit <[email protected]> wrote: >> I have to process a csv file from a business partner. Oddly (?) they >> don't quote text fields, and the Title field sometimes contains >> commas. So I wrote some code to count the commas in each line and if >> there were too many, I removed the extras and wrote the cleaned up >> file to the original filename for the rest of what I have to with that >> data > > That is terrible (of them). How do you determine which comma is the "extra"?
Yes, it is kinda disheartening, but I don't know if they distribute this file to others, and changing it might have ramifications. I take the line and split it on commas. Then get the length of the list. If its greater than 8, I append the item in the list that is after the Title field (I don't have the code with me -- i think its the 6th item) to the field that is the beginning of the title. Then I remove (pop) that field. Lather, rinse, repeat until there are 8 elements in the list. Then I join the list back with commas and write to the output file. > > > Ramit > > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > 712 Main Street | Houston, TX 77002 > work phone: 713 - 216 - 5423 > > -- > > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available at http://www.jpmorgan.com/pages/disclosures/email. > _______________________________________________ > Tutor maillist - [email protected] > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor -- Joel Goldstick _______________________________________________ Tutor maillist - [email protected] To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
