简体   繁体   English

如何从 python 的列表中打印选定的数字?

[英]How to print selected numbers from a list in python?

I want to print all atoms except H (hydrogen) from the pdb file.我想从 pdb 文件中打印除 H(氢)以外的所有原子。 Here is the file这是文件

https://github.com/mahesh27dx/molecular_phys.git https://github.com/mahesh27dx/molecular_phys.git

Following code prints the objects of the file以下代码打印文件的对象

import numpy as np
import mdtraj as md

coord = md.load('alanine-dipeptide-nowater.pdb')
atoms, bonds = coord.topology.to_dataframe()
atoms

The result looks like this结果看起来像这样在此处输入图像描述

From this table I want to print all the elements except H. I think it can be done in python using the list slicing.从这张表中,我想打印除 H 之外的所有元素。我认为可以使用列表切片在 python 中完成。 Could someone have any idea how it can be done?有人能知道怎么做吗? Thanks!谢谢!

You probably should clarify that you want help with mdtraj or pandas specifically.您可能应该澄清您需要mdtrajpandas的帮助。

Anyway, it's as simple as atoms.loc[atoms.element != 'H'] .无论如何,它就像atoms.loc[atoms.element != 'H']一样简单。

You can do the following:您可以执行以下操作:

print(*list(df[df.element!='H']['element']))

If you want the unique elements, you can do this:如果你想要独特的元素,你可以这样做:

print(*set(df[df.element!='H']['element']))

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM