我有一个有几列的csv。我需要将中间列合并为一个由管道分隔的列
我将如何做到这一点?
示例数据:
B032CN517,TRUE,Men's 4.2 oz. Long-Sleeve Henley,"""1151|0|5"";""994|6|47"";""964|48|-1"";",0.47,Broder,3150,,22.60,2XL,0,BLACK,Canvas,,,B032CN517,http://www.broderbros.com/images/bro/prodDetail/3150_51_p.jpg,Apparel,Activewear,Henleys & Jerseys
所需的输出
B032CN517,TRUE,Men's 4.2 oz. Long-Sleeve Henley,"""1151|0|5"";""994|6|47"";""964|48|-1"";",0.47,Broder,3150,,22.60,2XL,0,BLACK,Canvas,,,B032CN517,http://www.broderbros.com/images/bro/prodDetail/3150_51_p.jpg,Apparel|Activewear|Henleys & Jerseys
答案 0 :(得分:4)
我假设您将使用CSV模块读取该行,该行将列出该行中所有逗号分隔的项目。
然后很简单:
line = line[:-3] + ['|'.join(line[-3:])]