【发布时间】:2020-10-30 21:02:56
【问题描述】:
我有一个 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'])
这是一个失败。
有人可以帮助我吗?谢谢。
【问题讨论】:
-
尝试以下操作:
sns.countplot(x=df.Label, data=df[((df.Label != 'I-Protein') & (df.Label != 'I-DNA'))].
标签: python pandas plot label seaborn