Skip to content
Advertisement

Replace values ​in a column with similar values ​in another column with different size – Python

I have a dataframe with different values ​​in a column (about 6,000 rows), which I need to replace with similar (but differents) values ​​found in another dataframe, which has fewer rows.

Store Values to replace
Store A 05/15/21 Store A
The Store B 04/01/21 Store B
Store letter B 11/12/21 Store C
Store C 10/24/21 Store D
Store D 09/30/21
the Store C 05/13/21
Store letter D 07/01/21
Store letter A 08/29/21

The goal is for the final dataframe to look like this:

Store
Store A
Store B
Store B
Store C
Store D
Store C
Store D
Store A

Advertisement

Answer

Given df and df2:

JavaScript

Doing:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement