我有一个文件夹,其中包含几个系列的文本文件,每个文件都包含一行分析后的残差。它们的文件名如下:
'residual_x01'
'residual_x02'
...
'residual_y01'
'residual_y02'
...
'residual_z01'
'residual_z02'
文件的内容如下所示:
1 ### This is the file number in the series
c:\file\location\goes\here
983 1051 0 0 983 1051 ### other identifier
1.1 ### this is where the data I want starts
3.5
0.8
0.7
1.3
... ## so on for about a million lines.
使用Python,我想从这些文件中提取残差,连接为每个系列(即x、y、z)形成一个长文件,并在运行时删除每个文件的前三行,即形成以下内容:
1.1 ### data from first file of series 'residual_x01 / _y01 / _z01'
3.5
0.8
0.7
1.3
...
1.1 ### data from second file of series 'residual_x02 / _y02 / _z02'
3.5
0.8
0.7
1.3
...
1.1 ### data from third file of series 'residual_x03 / _y03 / _z03'
3.5
0.8
0.7
1.3
... ... and so on.
我不知道该怎么做,有人能帮忙吗
你没有提供太多的数据,所以我做了一些伪造的数据。我不想制作一堆文件,所以我只制作了三个假数据文件,但是代码应该适用于任意数量的文件,并且每个文件的长度也可以是可变的
假设您有以下三个文本文件:
文件/residential_x01.txt
文件/residential_x02.txt
文件/残差_y01.txt
代码:
输出:
对于每个系列,您可以使用以下代码创建一个包含所有文件行(每个文件的前3行除外)的文件:
根据您的需要更改
filenames
列表和output_file
。还可以调整lines_to_skip
变量相关问题 更多 >
编程相关推荐