我有这样的df:
ID LC
1 Corn
2 Forest/Shrubland/Deciduous Forest/Evergreen Forest/Mixed Forest
3 Blank_/Peas
我试图替换一些LC
项。
我正在使用此代码:
import pandas as pd
replace = {'Blank_/Peas': 'Other Crops', 'Forest/Shrubland/Deciduous Forest/Evergreen Forest/Mixed Forest': 'Forest/Shrub'}
df['LC'].replace(replace, regex=True, inplace=True)
但这会返回:
ID LC
1 Corn
2 Forest/Shrubland/Deciduous Forest/Evergreen Forest/Mixed Forest
3 Other Crops
我不确定为什么有些物品被替换而其他物品没有被替换。
这也不起作用:
df['LC'].replace(replace, inplace=True)