【发布时间】:2022-08-19 01:39:52
【问题描述】:
我需要分离一些我得到的数据。我正在使用 pandas DataFrame 来做到这一点。
这是我的问题之前的代码:
import pandas as pd
from sklearn.datasets import load_iris
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.svm import LinearSVC
from sklearn.metrics import ConfusionMatrixDisplay
arquivo_arff = arff.loadarff(r\"/content/Rice_MSC_Dataset.arff\")
dados = pd.DataFrame(arquivo_arff[0])
dados = dados[[\'MINOR_AXIS\', \'MAJOR_AXIS\', \'CLASS\']]
我已经完成了一个带有 5 个参数的散点图,以便使用此代码进行分析(0 个过滤器):
sns.scatterplot(
data=dados,
x=\"MINOR_AXIS\",
y=\"MAJOR_AXIS\",
hue=\"CLASS\")
plt.show()
我的问题:我只需要过滤物种 b\'Basmati\' 和 b\'Ipsala\',但我无法做到这一点,我不知道为什么。
\"CLASS\" 参数为:b\'Basmati\',b\'Arborio\',b\'Jasmine\',b\'Ipsala\',bKaracadag\'
但是,在我使用的 \".arff\" 文件中,名称只有 \"Basmati,Arborio,Jasmine,Ipsala,Karacadag\"
我尝试过的: 仅过滤这两个物种,使用以下代码:
dados = dados[dados[\'CLASS\'].isin([\"\" \"b\'Arborio\'\" \"\", \"\" \"b\'Ipsala\'\" \"\"])]
没用。我怎样才能解决这个问题?
-
使用
.isin([\"Arborio\", \"Ipsala\"])]或.isin([b\"Arborio\", b\"Ipsala\"])]有效吗? -
.isin([b\"Arborio\", b\"Ipsala\"])]工作。非常感谢!
标签: python pandas scatter-plot