Thousands of values need to be replaced by a simpler naming format. For example, the original dataframe's naming is AB5648, CD5678, EF5468, etc. and need to be replaced by HH_1, HH_2, HH_3 and so on, in accordance with the correspondence table I created. Correspondence table includes values to replace and to be replaced.
Original file = df_temp
Filename = 'HH_number_Old.csv'
Filename = 'HH_number_New.csv'
Old New
AB1321 HH_1
CD5678 HH_2
EF5468 HH_3
EF5468 HH_3
EF5438 HH_4
EF5368 HH_5
EF5068 HH_6
EF5468 HH_7
EF5458 HH_8
EF5168 HH_9
..... .....
XZ5465 HH_3000
Here's what I tried.
for i in range (3000):
print(HH_number_old[i])
print(HH_number_new[i])
temp_fin = df_temp.replace({HH_contract[i], HH_no[i]}, inplace=True)
#temp_fin is the resultant dataframe with replaced values
Result = temp_fin file is empty.
Replacing works when I try a specific number of [i] as below.
temp_fin = df_temp.replace (HH_number_old[1], HH_number_new[1])