Conditional replacement in pandas
It may just be simpler to do it a different way:
oldNewMap = {1: 3, 2: 3, 3: 4, 4: 2, 5: 1, 91: 6}df['ethnicity'][df.year==year] = df['ethnicity'][df.year==year].map(oldNewMap)
It may just be simpler to do it a different way:
oldNewMap = {1: 3, 2: 3, 3: 4, 4: 2, 5: 1, 91: 6}df['ethnicity'][df.year==year] = df['ethnicity'][df.year==year].map(oldNewMap)