【问题标题】:How to use dictonary or other method effecintly to clean data如何有效地使用字典或其他方法来清理数据
【发布时间】:2020-09-03 02:28:34
【问题描述】:

我正在为部门处理包含大量代码的数据集。我有其他解码部门的论文有没有有效的方法来合并或替换。

第一个数据集:

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]

预期:

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

【问题讨论】:

    标签: pandas dataframe data-manipulation


    【解决方案1】:

    让我们试试explode 然后merge

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

    【讨论】:

      猜你喜欢
      • 2020-07-04
      • 1970-01-01
      • 2016-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-24
      • 2021-10-03
      • 1970-01-01
      相关资源
      最近更新 更多