TransWikia.com

How to use dictonary or other method effecintly to clean data

Stack Overflow Asked by gannu on November 13, 2020

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          

One Answer

Let us try explode then merge

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

Answered by BEN_YO on November 13, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP