There is a data frame like below:
A | B |
---|---|
1 | 12 |
84 | 15 |
51 | 42 |
2 | 10 |
Each value shows the position of a string in a list. For example, list A=[Cat, Dog, Cow, ...] Therefore, the first value in column A should be Dog. How can I replace this values in this data frame fast. This data frame has more than 1 million rows. I wrote the code below, but it seems that it takes ages to run!!
for i in range (0, len(df)):
a = df.iloc[i,0]
df.iloc[i,0] = A[a]
b = df.iloc[i,1]
df.iloc[i,1] = B[b]