gannu
gannu

Reputation: 109

How to use dictonary or other method effecintly to clean data

Iam working on a dataset with lots of code for the department. I have other paper that decodes the department is there efficient way to combine or replace.

First Dataset:

Location        DeptCode
Delhi           12B
Gurgoun         12D 
Hydrabad        13A 
Punjab          20A
Jhansi          31B

Below is the code: 
Department        DeptCode
Electronics       [12A, 12B, 12C, 12D, 12E ........12Z]
Electronics       [13A,13B,.......13Z]
Grocery           20A
Grocery           [31A,31B,31C,.........31Z]

Expected:

Department        DeptCode     Location
Electronics       12B          Delhi
Electronics       12D          Gurgoun
Electronics       13A          Hydrabad
Grocery           20A          Punjab
Grocery           31B          Jhansi          

Upvotes: 0

Views: 17

Answers (1)

BENY
BENY

Reputation: 323316

Let us try explode then merge

Out = df1.merge(df2.explode('DeptCode'), on='Deptcode', how='left')

Upvotes: 1

Related Questions