currently, I have a dataframe that looks like this
| Heading 1 | Heading 2 |
|---|---|
| 01 | 3G |
| 02 | 94 |
| 03 | 78 |
| 04 | 3L |
The Heading 2 values are wrong and suppose to be 113G, 0994, 0978, and 113N.
My attempt at this looks like
Correct_List = [113G, 0994, 0978, 113N]
Incorrect_List = [94, 3G, 3L, 78]
def correcting(df, list_1, list_2):
for (two_digit, four_digit) in zip(list_1, list_2) :
if two_digit == four_digit[-2:]:
df['DDIST'] = np.where((df.DDIST == two_digit), four_digit, df.DDIST)
return df
I ran the function and checked the data frame, but nothing happened.
The desired output is:
| Heading 1 | Heading 2 |
|---|---|
| 01 | 113G |
| 02 | 0994 |
| 03 | 0978 |
| 04 | 113L |
Also, any method better than the loop would also be appreciated, since the actual data frame and loop are very big