这里有一个数据集:
Dataset
我想将数值映射到CASE_STATUS
值
df.CASE_STATUS.value_counts()
CERTIFIED 2615623
CERTIFIED-WITHDRAWN 202659
DENIED 94346
这是我的工作,但出现
string indices must be integers, not str
错误:for dataset in df:
dataset['CASE_STATUS'] = dataset['CASE_STATUS'].map( {'CERTIFIED':1 , 'CERTIFIED-WITHDRAWN': 1, 'DENIED': 0} ).astype(int)
如何将值映射到
CASE_STATUS
? 最佳答案
我认为您不需要for
循环:
dict_map = {'CERTIFIED':1 , 'CERTIFIED-WITHDRAWN': 1, 'DENIED': 0}
df['CASE_STATUS'] = df['CASE_STATUS'].map(dict_map)
df['CASE_STATUS'] = df['CASE_STATUS'].astype(int)