我有以下格式的文本文件:
10900 PART1 3211034
10900 PART2 3400458
10900 PART4 3183857
10900 PART3 4152115
10900 PART5 3366650
10900 PART6 1548868
10920 PART3 4154075
10920 PART2 3404018
10920 PART1 3207571
10920 PART4 3178505
10920 PART6 1882924
10920 PART5 3363267
10940 PART6 2183534
10940 PART3 4153924
10940 PART4 3178554
10940 PART1 3207436
10940 PART5 3363585
10940 PART2 3404220
我想分割文件-首先,按第一列;第二,第三列的总和不超过10000000。在
以下是我根据第一列拆分文件的代码:
^{pr2}$输出如我所愿:
^{3}$我需要在每个文件的第一列和第三列的总和(3211034+3400458+3183857)不大于10000000,以此类推,对于其他文件。。。。。。。。。。。。。在
我不明白你想怎么处理第一个专栏。但是,这里有一些python遵守了对第二列和的限制
文件ID=itertools.count(一) 以open('path/to/file')作为填充: 总和=0 阈值=10000000 outfile=open(“文件%d”%fileID,“w”)
希望这有帮助
{1>在这里使用
这将创建7个文件。以下是
^{pr2}$grep . File*
的输出,显示了这些文件中的每一个的内容:如果我没有弄错你的说明书,下面的内容可能对你有用。基本上,它检查第二个字段是否大于1000,如果大于1000,则将其打印到
filec
(c
是计数器),然后重置第二个字段的总和并增加文件计数器,等等如果要在第一列上拆分和第三列的和:
^{pr2}$是的,我知道这可以缩短。。。在
相关问题 更多 >
编程相关推荐