replace the use of pandas

Alternatively either replace a column, a row may be replaced

replace(self, to_replace=None, value=None, inplace=False, limit=None, regex=False, method='pad', axis=None)

The parameters passed in either list, it can be a dictionary, but the incoming dictionaries, key and value must not be repeated (strict), otherwise an error 

ValueError: Replacement not allowed with overlapping keys and values

For example, passed the following dictionary is problematic

mapping_dict = {"prodcode_type":{
    "1":"0",
    "2":"3",
    "3":"1",
    "4":"1",
    "5":"1",
    "6":"2",
    "7":"b",
    "8":"z",
    "9":"2",
    "a":"5",
    "b":"1",
    "d":"4",
    "t":"e",
    "u":"l"
}}
mfbaseinfo = mfbaseinfo.replace(mapping_dict)  

 

At this point if we do have such a demand, you can put the dictionary into a list, you can solve.

mfbaseinfo['prodcode_type'].replace(['1','2','3','4','5','6','7','8','9','a','b','d','t','u'],
                                    ['0','3','1','1','1','2','b','z','2','5','1','4','e','l'],inplace=True)

 The remaining usage reference https://www.jianshu.com/p/2557a805211f 

Guess you like

Origin www.cnblogs.com/xiaodongsuibi/p/12175366.html