我有一個有10列,每列記錄如下製表符分隔文本文件:Python的 - 轉換製表符分隔的文件轉換成CSV以特定的方式
p001 64 20141209 meals (attendees) ML ENTER Entertainment xyz Restaurants 6.0 "_e' Restaurants (123) 456-7890 \r\n FORUM \r\n ,Around \r\n\r\n':33 113-2 \r\n\r\n 8440 XYZ09'15 1:11PM \r\n\r\n 1 Burger 6.00 \r\n\r\n SSIONS 6.00 \r\n TOTAL PAID 6 .00 \r\n XXXXXXXXXXX2012 XX/XX \r\n XYZ EXPRESS
6.00 \r\n\r\n\r\n 7,-10(YOU! FOR DINING WITH US! \r\n\r\n 113-2 \r\n\r\nYour r is: 840 \r\n"
P.S:最後一欄已文本括在「」。而我的第一列不是唯一的。
我想將此文本文件轉換爲csv文件,以便我只從記錄的第1,2,8,9,10列中選取數據。另外,所有的數據都應該包含在「」中。
例如,上面記錄着應轉換爲輸出CSV文件中的以下行:
"p001","64","xyz Restaurants","6.0","_e' Restaurants (123) 456-7890 \r\n FORUM \r\n ,Around \r\n\r\n':33 113-2 \r\n\r\n 8440 XYZ09'15 1:11PM \r\n\r\n 1 Burger 6.00 \r\n\r\n SSIONS 6.00 \r\n TOTAL PAID 6 .00 \r\n XXXXXXXXXXX2012 XX/XX \r\n XYZ EXPRESS
6.00 \r\n\r\n\r\n 7,-10(YOU! FOR DINING WITH US! \r\n\r\n 113-2 \r\n\r\nYour r is: 840 \r\n"
[讀取並解析TSV文件,然後將其保存爲CSV(\ * efficient \ *)](可能會重複)(http://stackoverflow.com/questions/13992971/reading-and-parsing-a- tsv-file-then-manipulation-it-for-saving-as-csv-efficie) –