【发布时间】:2022-01-07 12:31:33
【问题描述】:
列类有 2 个值选项,“b”或“s”。我正在尝试显示一个图形/图表,显示有多少是“b”,有多少是“s”。当它们都在同一列时,我不知道该怎么做。
当前代码显示的是散点图,但我想使用“类”列中的数据。
import pandas as pd
import matplotlib.pylab as plt
import numpy as np
#df = df.groupby('class')['class'].count()
#print(df)
df = pd.DataFrame(np.random.randint(0,10,size=(5, 2)), columns=['x','y'])
df['class'] = ['Benign','Malware','Benign','Malware','Malware']
# plot groupby results on the same canvas
fig, ax = plt.subplots(figsize=(8,6))
for n, grp in df.groupby('class'):
ax.scatter(x = "x", y = "y", data=grp, label=n)
ax.legend(title="Label")
plt.show()
【问题讨论】:
-
“b”有多少,“s”有多少是什么意思?
-
数据有一个名为“class”的列,该列中的值为“b”或“s”。我试图仅从该列显示有多少条目是“b”以及有多少是“s”
标签: python matplotlib jupyter-notebook