简体   繁体   English

如何在 select 行中有一个以上的值 Pandas DataFrame

[英]How to select rows with more than one value in Pandas DataFrame

I have a DataFrame that looks like this:我有一个 DataFrame,看起来像这样:

    Entry   ribosome protein    PDB
0   P46782            s5         4ug0;4v6x;5a2q;5aj0;5flx;5lks;5oa3;5t2c;5vyc;6...
1   P0A7W3            s5         5wf0;5wfs;6awb;6awc;6awd
2   A2RNN6            s5         5myj
3   Q5SHQ5            s5         1fjg;1fka;1hnw;1hnx;1hnz;1hr0;1i94;1i95;1i96;1...
4   Q2YYL4            s5         6fxc
5   A0QSG6            s5         5o5j;5o61;5xyu;5zeb;5zep;5zeu;6dzi;6dzk
6   P33759            s5         5mrc;5mre;5mrf`

I need to extract rows that have more than one entry in a column 'PDB'.我需要提取在“PDB”列中具有多个条目的行。 For example, I want to have the DataFrame that shows rows without "6fxc" and "5myj" (single entries) in this case, but only multiple PDBs like "5mrc;5mre;5mrf".例如,在这种情况下,我希望 DataFrame 显示没有“6fxc”和“5myj”(单个条目)的行,但只有多个 PDB,如“5mrc;5mre;5mrf”。

How to do it?怎么做?

This is only a fragment of a huge dataframe with such data, that I need to filter this way.这只是包含此类数据的巨大 dataframe 的一部分,我需要以这种方式进行过滤。

May be you can use something with split and len and followed by filtering it:也许你可以使用splitlen的东西然后过滤它:

df[df['PDB'].str.split(';').str.len()>1]

Following comment, you can also try simply counting ;在评论之后,您也可以尝试简单地计数; as following:如下:

df[df['PDB'].str.count(";")>0]

You can omit the rows whose PDB field contains no ;您可以省略其PDB字段不包含任何行; like this:像这样:

df[df['PDB'].str.contains(';')]

暂无
暂无

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

相关问题 如何在 Pandas 数据框中选择值出现多次的行 - How to select rows in Pandas dataframe where value appears more than once 如何只保留pandas DataFrame中具有多个值的行? - How to only keep rows which have more than one value in a pandas DataFrame? 如何在熊猫数据框中找到与另一列中的多个值相对应的列中具有值的所有行? - How can I find all rows with a value in one column which corresponds to more than one value in another column in a pandas dataframe? 数据帧pandas中使用逗号的多个值 - more than one value with comma in dataframe pandas 如何在 Pandas 的单元格中删除具有多个值的行 - How to remove rows with more than one value in a cell in Pandas 如何在 select 行中至少有一个分类值 pandas DataFrame - How to select rows with at least one categorical value in pandas DataFrame pandas DataFrame:如何将单词判为单词并选择10个单词以上的行? - pandas DataFrame: how to sentence into words and select rows that have more than 10 words? 如何创建一个 dataframe 只选择在 Pandas 中值超过 avg +/* 标准偏差的行? - How to create a dataframe that only selects rows that have value more than avg +/* standard deviation in Pandas? 在熊猫数据框中的一个列中有多个值时如何计算值计数 - how to calculate value counts when we have more than one value in a colum in pandas dataframe 使用pandas数据框中的多个行或列值进行计算 - using more than one row or column value in a pandas dataframe for a calculation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM