Replace items in column based on list Replace items in column based on list pandas pandas

Replace items in column based on list


If you create a dictionary that maps from list1 to list2 then you can use Series.map:

df = pd.read_clipboard()list1 = ['19990506', '19990607', '20000802']list2 = ['1999201', '1999232', '2000252']# When I read in your data I get ints in the Date column#   so I need ints in the replacement map, if you have#   strings then remove the int() conversionsreplacement_map = {int(i1): int(i2) for i1, i2 in zip(list1, list2)}df['Date'] = df['Date'].map(replacement_map)dfOut[13]:       Date  Value0  1999201    0.61  1999201    0.82  1999232    1.23  2000252    0.4