Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.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 - Fatal编程技术网

在Python中重新排列缩进后排列列

在Python中重新排列缩进后排列列,python,Python,我的数据集如下所示: atom 01 B HEL A1001 -1.09 32.90 22.99 atom 02 C ARG A1002 -3.22 22.89 12.00 atom 03 C1 ARG A1003 -2.99 18.32 22.13 atom 04 CW2AARG A1004 -2.22 19.99 29.84 atom 05 WS HEL A1005 -3.22 18.33 14.21 … 我要找的是纠正第三行缩进问题,或者在AARG之前添加一个

我的数据集如下所示:

atom 01 B   HEL A1001 -1.09 32.90 22.99  
atom 02 C   ARG A1002 -3.22 22.89 12.00  
atom 03 C1  ARG A1003 -2.99 18.32 22.13  
atom 04 CW2AARG A1004 -2.22 19.99 29.84  
atom 05 WS  HEL A1005 -3.22 18.33 14.21

我要找的是纠正第三行缩进问题,或者在AARG之前添加一个“空格”,或者创建一个空格列。最终看起来应该是

atom 01 B    HEL A1001 -1.09 32.90 22.99  
atom 02 C    ARG A1002 -3.22 22.89 12.00  
atom 03 C1   ARG A1003 -2.99 18.32 22.13  
atom 04 CW2  AARG A1004 -2.22 19.99 29.84  
atom 05 WS   HEL A1005 -3.22 18.33 14.21
对地图中的线条使用
(str.split,inp):x=线条[2]

我试图通过使用
line[2]
来选择一列,但是我得到了一个错误的列选择,因为
CW2AARG
作为单个列条目出现,而不是
line[2]
CW2
AARG
line[3]


关于我应该如何改变我的方法的任何想法…

在假设发生此列连接时,您的氨基酸ID将是四个字符长的情况下,并且这是唯一有问题的列,此代码应该可以工作:

pdb_data = []
for line in open('input.txt'):
    line = line.split()
    if len(line)<8:
        pre = line[0:2]
        post = line[3:]
        col3 = line[2][:-4]
        col4 = line[2][-4:]
        new_line = pre+[col3,col4]+post
        pdb_data.append(new_line)
    else:
        pdb_data.append(line)
pdb_数据=[]
对于打开的行('input.txt'):
line=line.split()

如果是len(line)请尝试切片方法以实现您想要的效果。
不要想得那么复杂。

使用
map(str.split,inp)
只会使它变得复杂。

你能显示出不起作用的代码吗(在那里你“得到了一个错误的列选择”?)可能的重复根本不一样?当前询问者的问题是,一个列已与另一个列连接,他需要将其正确拆分。是的!一点也不一样。当这种情况发生时,氨基酸ID总是四个字母长吗?