How to Normalize Names

前端 未结 2 1738
情歌与酒
情歌与酒 2020-12-16 05:43

I am using pandas dataframes and I have data where I have customers per company. However, the company titles vary slightly but ultimately affect the data. Example:



        
2条回答
  •  一整个雨季
    2020-12-16 05:47

    splitCompaniesSet = map( lambda cmpnyName : set( map( lambda name : name.split(" "), cmpnyName ) ), dataFrame['Company'] )

    I think that's right.

    Basically create a list of sets, each set has the company name split. Then, starting with the first element, find the set intersection of every other element with that one. For every non-empty intersection, change the name to whatever the simplest match was among all the non-empty resulting sets, i.e. take one more set intersection with all the nonempty sets and set the result to be the company name for all those non-empty matches.

    Then go on to the next Company that resulted in an empty set when intersected with the first company name. Then do this for the next Company that was empty for the first two you tried, and so on.

    There's probably a more efficient way to do it, though.

提交回复
热议问题