分类器:输出错误

时间:2019-04-11 15:40:44

标签: pandas classification

我的数据框看起来像这样:

df
Annotation_A    Annotation_B
first           Boarding
first           Alighting
last            Boarding
last            Alighting
first           Boarding
first           Alighting
last            Alighting

我使用以下代码分析了数据:

df = pd.read_csv('data.csv')
def classifier(row):
    if row["Annotation_A"] == "first" and row["Annotation_B"] == "Boarding":
        return "match-1"
    elif row["Annotation_A"] == "last" and row["Annotation_B"] == "Alighting":
        return "match-2"
    else:
        return "Un-match"
df["Matching"] = df.apply(classifier, axis=1)

我要创建一个包含“ match-1和match-2”的新列“ match”。但是,我得到了错误的输出,如下所示:

Annotation_A    Annotation_B    Matching
first           Boarding        match-1
first           Alighting       Un-match
last            Boarding        Un-match
last            Alighting       Un-match -->must be "match-2"
first           Boarding        match-1
first           Alighting       Un-match
last            Alighting       Un-match -->must be "match-2"

0 个答案:

没有答案