【发布时间】:2019-12-09 12:12:16
【问题描述】:
我有一本将数字标签与分类标签相关联的字典。
dict = {
0:'cat',
1:'dog',
2:'fish
}
我的数据框(df)输出如下:
Feature | Feature Value | Feature1 | Feature1 Value
Pet 1 Thing 1
Person Steve Pet 1
Place Texas Place Virginia
我想将“1”替换为“狗”。
我试过了。
df.replace({df.loc[df['Feature'] == 'Pet']: dict})
但是,我知道这只是在匹配 Feature 列,而不是从 Feature 值中提取值以在字典中匹配。
我的数据框(df)输出应该是:
Feature | Feature Value | Feature1 | Feature1 Value
Pet dog Thing 1
Person Steve Pet dog
Place Texas Place Virginia
【问题讨论】: