我目前有以下代码 - 我正在尝试根据列在一个数据框中获取匹配的行Last Name。
def rule(row):
name = row['Last Name']
return rules.loc[rules['Last Name'] == name]['Type']
df['Type'] = df.apply(rule, axis=1)
当我运行它时,我得到一个错误,因为方法== name中的rule- 我该如何修复它?
ValueError: ('Buffer has wrong number of dimensions (expected 1, got 0)', 'occurred at index 0')
这rules看起来像:
Last Name Type
0 Smith A
1 Doe B
和df:
Name First Name Last Name
0 John Smith John Smith
1 Jane Doe Jane Doe
2 John Doe John Doe
我希望决赛看起来像:
Name First Name Last Name Type
0 John Smith John Smith A
1 Jane Doe Jane Doe B
2 John Doe John Doe B
编辑:添加示例rules和df
翻过高山走不出你
相关分类