Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中,从文本文件导入行时跳过文本文件上下的某些行_Python_Eol - Fatal编程技术网

在python中,从文本文件导入行时跳过文本文件上下的某些行

在python中,从文本文件导入行时跳过文本文件上下的某些行,python,eol,Python,Eol,我是python新手,需要提取存储在文本文件中的swat模型输出。我成功地从下面的代码(Stackoverflow中修改的示例代码)中提取了我需要的文本文件行,但仍然由输出的顶部和底部的空行组成 此方法为原始文件(附加到您的)提供了一些不需要的空行 我的文本文件共有1879行,我试图准确地读取940到1732之间的行,上面和下面没有任何空行 从文件中导入感兴趣的文本行后,我想为每列指定列名。Python总是在每个空白空间之后考虑该列。 ..... .... line of interest st

我是python新手,需要提取存储在文本文件中的swat模型输出。我成功地从下面的代码(Stackoverflow中修改的示例代码)中提取了我需要的文本文件行,但仍然由输出的顶部和底部的空行组成

此方法为原始文件(附加到您的)提供了一些不需要的空行 我的文本文件共有1879行,我试图准确地读取940到1732之间的行,上面和下面没有任何空行

从文件中导入感兴趣的文本行后,我想为每列指定列名。Python总是在每个空白空间

之后考虑该列。
.....
.... line of interest starts from below line relates to 790th line of my text file
HRU  SUB CPMN SOIL    AREAkm2     CN    AWCmm    USLE_LS   IRRmm AUTONkh 
1   1 FRSDForSoil .356E+00        66.19  325.40    6.45    0.00    0.00               
2   1 BERMSealedGr.180E-02        78.90    20.00    3.82   0.00   300.00      
....
.....
7   2 RYE FlatDryS.900E-02        72.12    359.50   2.76    0.00     85.28           
....
792 21 SOYBRicePadS.630E-02       75.45    123.00   1.69    0.00     0.00           
在导入与1732我的测试文件的行相关的行时,不需要在上面一行之后再行

当使用
usecols
指定列名时,由于每行中的空间不均匀(主要是由于第三列(文本和数字的混合不均匀),因此每行的列号不相等。现在,我想将第三列分为3列,即CPNM SOL和Area

我希望得到任何建议。
这将极大地帮助我的研究工作

观察:不要对文件名和文件句柄使用相同的变量
outhru
。确定,但仍存在将子cpmn soi和arekm2拆分为该文件中的单个列的问题
.....
.... line of interest starts from below line relates to 790th line of my text file
HRU  SUB CPMN SOIL    AREAkm2     CN    AWCmm    USLE_LS   IRRmm AUTONkh 
1   1 FRSDForSoil .356E+00        66.19  325.40    6.45    0.00    0.00               
2   1 BERMSealedGr.180E-02        78.90    20.00    3.82   0.00   300.00      
....
.....
7   2 RYE FlatDryS.900E-02        72.12    359.50   2.76    0.00     85.28           
....
792 21 SOYBRicePadS.630E-02       75.45    123.00   1.69    0.00     0.00