简体   繁体   English

如何在提取后使用python删除特定的列

[英]how to remove a certain column after extraction, using python

I have a txt file, "as following:" 我有一个txt文件,“如下”:

.
.
.
-----------------------
MULLIKEN ATOMIC CHARGES
-----------------------
   0 C :   -0.157853
   1 C :   -0.156875
   2 C :   -0.143714
   3 C :   -0.140489
   4 S :    0.058926
   5 H :    0.128758
   6 H :    0.128814
   7 H :    0.142420
   8 H :    0.140013
Sum of atomic charges:   -0.0000000

------------------------
.
..
.

, and I have already extracted some of it, like this: ,而我已经提取了其中的一部分,如下所示:

stringy = []

with open('FILE.txt', 'rb') as f:
     textfile_temp = f.read()
     print textfile_temp.split('first ATOMIC CHARGES')[1].split("My charges :   -0.0000000")[0].replace('-----------------------\n', '')

the result is good, but I want to remove the third column (" : ") [2] 结果很好,但是我想删除第三列 (“:”)[2]

   0 C :   -0.157853
   1 C :   -0.156875
   2 C :   -0.143714
   3 C :   -0.140489
   4 S :    0.058926
   5 H :    0.128758
   6 H :    0.128814
   7 H :    0.142420
   8 H :    0.140013

This should do it: 应该这样做:

stringy = []

with open('FILE.txt', 'rb') as f:
     textfile_temp = f.read()
     textfile_temp = textfile_temp.split('MULLIKEN ATOMIC CHARGES')[1].split("Sum of atomic charges:   -0.0000000")[0].replace('-----------------------\n', '')
     for line in textfile_temp.split("\n"):
         print(line.replace(' : ', ''))

But I'm not able to test it as your example string you put does not match the split you have in your code, as eg MULLIKEN ATOMIC CHARGES is not in the string. 但是我无法对其进行测试,因为您输入的示例字符串与代码中的split不匹配,例如,字符串中没有MULLIKEN ATOMIC CHARGES

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在使用python提取部件后删除某个字符 - How to remove a certain character after the extraction of a part, using python 如何使用 Python 删除列中单元格的某些部分? - How do I remove certain parts of cells in a column using Python? 如何使用 Python 3 删除某个字符后的所有字符 - How to remove all characters after a certain character using Python 3 使用Python进行嵌套列提取 - Nested column extraction using Python 如何使用 OCR Pytesseract 删除文本提取后出现的箭头符号 - How to remove the arrow sign coming after text extraction using OCR Pytesseract 如何使用Python删除Excel文件中具有特定值的列中的行 - How to remove rows in a column with certain value in Excel file with Python 如何删除Python字符串中2个特定字符之后的字符? - How to remove characters after 2 certain characters in a Python string? 如何在使用 Python 提取关键字期间更改 csv 输出中的列名? - How to change column names in csv output during keyword extraction using Python? 如何使用Python在Excel中删除第一列 - How to remove the first column in Excel using Python 使用 Python 对列中的多个值进行复杂的提取和转换 - Complex extraction and transformation of multiple values within a column using Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM