pandas中的replace用法
replace既可以替换某列,也可以替换某行
replace(self, to_replace=None, value=None, inplace=False, limit=None, regex=False, method='pad', axis=None)
传入的参数既可以是列表,也可以是字典,但是传入的字典,key和value必须不能重复(严格),否则报错
ValueError: Replacement not allowed with overlapping keys and values
例如传入如下字典是有问题的
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)
此时如果我们确实有这样的需求,可以把字典改成列表,就可解决。
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)
既然无论如何时间都会过去,为什么不选择做些有意义的事情呢