如何改写一个CSV文件
现在要对一个csv文件(其中数据冗余比较大)进行改写,可以理解为把原csv文件拉直,各位大牛帮忙看下有什么方法可以实现(由于原文件比较大,我可以发到各位邮箱),谢谢!
改写后格式为:SEDOL(序号,如656099),FPE(预测年份,包含FPE1:12/31/2011和FPE2:12/31/2012),Date(预测日期),BROKER(经纪人),EPS,BPS,DPS,TP。。。
改写后的格式如下:
SEDOL FPE Date BROKER EPS BPS DPS TP
656099 12/31/2011 03/10/2011 1171 1.07793 7.09544 0.213219 ...
656099 12/31/2012 03/10/2011 1171 1.1727 8.05493 0.23691 ...
改写前格式为:
656099^ EPS_FPE1 12/31/2011
EPS_FPE2 12/31/2012
EPS_BROKER1 1171 1788 1545
EPS_DATE1 03/10/2011 03/11/2011 03/16/2011
EPS_VALUE1 1.07793 1.06614 1.34071
BPS_BROKER1 1171 77 686
BPS_DATE1 03/10/2011 03/23/2011 03/23/2011
BPS_VALUE1 7.09544 9.86059 7.75888
DPS_BROKER1 1171 14492 143
DPS_DATE1 03/10/2011 03/22/2011 03/22/2011
DPS_VALUE1 0.213219 0.237728 0.225842
TP_BROKER1 14552 1171 1746
TP_DATE1 @NA 03/10/2011 03/10/2011
TP_VALUE1 NA 19 20.94
SALES_BROKER1 1171 1171 14492
SALES_DATE1 03/10/2011 03/21/2011 03/22/2011
SALES_VALUE1 26326.6 25866.8 27824
NET_BROKER1 1171 1788 14492
NET_DATE1 03/10/2011 03/11/2011 03/22/2011
NET_VALUE1 5273.6 4773.98 5518.73
EPS_BROKER2 1171 1788 1545
EPS_DATE2 03/10/2011 03/11/2011 03/16/2011
EPS_VALUE2 1.1727 1.232 1.6136
BPS_BROKER2 1171 143 77
BPS_DATE2 03/10/2011 03/22/2011 03/23/2011
BPS_VALUE2 8.05493 8.54633 11.0485
DPS_BROKER2 1171 14492 143
DPS_DATE2 03/10/2011 03/22/2011 03/22/2011
DPS_VALUE2 0.23691 0.273388 0.261501
TP_BROKER2 14552 1171 1746
TP_DATE2 @NA 03/10/2011 03/10/2011
TP_VALUE2 NA 19 20.94
SALES_BROKER2 1171 1171 14492
SALES_DATE2 03/10/2011 03/21/2011 03/22/2011
SALES_VALUE2 29548.5 29098.6 31810.4
NET_BROKER2 1171 1788 14492
NET_DATE2 03/10/2011 03/11/2011 03/22/2011
NET_VALUE2 5724.91 5549.9 6148.66
RATING_BR 1788 1545 1169
RATING_DATE 03/11/2011 03/16/2011 03/22/2011
RATING_VL Overweight Buy Overweight
CURRENCY HKD
B56FB9^ 12/31/2011
12/31/2012
1171 105 15680
03/09/2011 @NA 04/25/2011
0.094786 NA 0.193
1171 105 15680
03/09/2011 @NA 04/25/2011
1.24407 NA 1.034
1171 105 15680
03/09/2011 @NA 04/25/2011
0 NA 0.048
1171 105 15680
03/09/2011 @NA 04/25/2011
1.64 NA 1.2
1171 105 15680
03/09/2011 @NA 04/25/2011
2645.72 NA 6202.78
1171 105 15680
03/09/2011 @NA 04/25/2011
236.965 NA 481.056
1171 105 15680
03/09/2011 @NA 04/25/2011
0.189573 NA 0.249
1171 105 15680
03/09/2011 @NA 04/25/2011
1.74169 NA 1.221
1171 105 15680
03/09/2011 @NA 04/25/2011
0 NA 0.062
1171 105 15680
03/09/2011 @NA 04/25/2011
1.64 NA 1.2
1171 105 15680
03/09/2011 @NA 04/25/2011
4723.91 NA 6826.55
1171 105 15680
03/09/2011 @NA 04/25/2011
479.855 NA 619.881
1171 15680 1377
03/09/2011 04/25/2011 04/26/2011
Hold Sell Sell
------解决方案--------------------
csv可以理解为修改了后缀名的txt文件
直接操作就行了