繁体   English   中英

如何从数据框中的列中选择多个特定值进行绘图

[英]How to select multiple specific values from a column in dataframe for plotting

我有一个 DataFrame,其中包含一个名为“Label”的分类数据列。 这是 df.Label.value_counts() 代码的输出。

    O              382963
    B-protein       30269
    I-protein       24848
    I-DNA           15774
    B-DNA            9533
    I-cell_type      8748
    I-cell_line      7387
    B-cell_type      6718
    B-cell_line      3830
    I-RNA            1530
    B-RNA             951

    

我想使用 seaborn 库中的 countplot() 来绘制这些值,但我只想绘制 B-label 值的计数,而不是 Label 列中的所有值。

我试过这个

   sns.countplot(x=df.Label, data=df[-(df.Label == 'I-Protein')]) 

它仅适用于 I-Protein 标签。 然后我尝试减去其他特定值,但没有用。 例如我试过这个:

   sns.countplot(x=df.Label, data=df[-(df.Label == 'I-Protein' or 'I-DNA']) 

这是一个失败。

有人能帮我吗? 谢谢你。

您可以制作一个 DataFrame 仅用于绘图。 通过这种方式,您可以在将数据发送到 Seaborn 之前测试和调试数据:

df_plot = df[df['Label'].str.startswith('B-')]
sns.countplot(x='Label', data=df_plot)

在此处输入图片说明

暂无
暂无

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

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