一行拆多行,动态列

针对带有特定前缀的CSV文件,需要转换为新的CSV格式,包括小写化头衔、删除头衔前缀、合并共享部分名称的列,并保留原始行的特殊值。使用SPL语言可以实现动态转换,处理过程中需要处理未知数量和名称的列,同时确保具有特定标识(如'Inc')的列在合并时得以保留。
摘要由CSDN通过智能技术生成

【问题】

I have a CSV file whose awful format I cannot change (simplified here):

Inc,a_One,a_Two,a_Three,b_One,b_Two,b_Three
1,1,1.5,"5 Things",2,2.5,"10 Things"
2,5,5.5,"10 Things",6,6.5,"20 Things"
Inc,a_One,a_Two,a_Three,b_One,b_Two,b_Three
3,9,9.5,"15 Things",10,10.5,"30 Things"

My desired output is a new CSV containing:

inc,label,one,two,three
1,"a",1,1.5,"5 Things"
2,"a",5,5.5,"10 Things"
3,"a",9,9.5,"15 Things"
1,"b",2,2.5,"10 Things"
2,"b",6,6.5,"20 Things"
3,"b",10,10.5,"30 Things"

Basically:

  • lowercase the headers
  • strip off header prefixes and preserve them by adding them to a new column
  • remove header repetitions in later rows
  • stack each column that shares the latter part of their names (e.g. a_On
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值