Home>

I need to do replace data with my DF. I know how to do this through map in the case when I need to replace one value with another, but I need to replace several values. Is there a better way to do this?

sql_huawei_bsc_GEXT2GCELL ['BSC']= sql_huawei_bsc_GEXT2GCELL ['BSC']. map (lambda x: (x.replace ('22279', '115')))
sql_huawei_bsc_GEXT2GCELL ['BSC']= sql_huawei_bsc_GEXT2GCELL ['BSC']. map (lambda x: (x.replace ('22285', '121')))
sql_huawei_bsc_GEXT2GCELL ['BSC']= sql_huawei_bsc_GEXT2GCELL ['BSC']. map (lambda x: (x.replace ('22381', '523')))
sql_huawei_bsc_GEXT2GCELL ['BSC']= sql_huawei_bsc_GEXT2GCELL ['BSC']. map (lambda x: (x.replace ('12312', '723')))
sql_huawei_bsc_GEXT2GCELL ['BSC']= sql_huawei_bsc_GEXT2GCELL ['BSC']. map (lambda x: (x.replace ('12351', '725')))

And in a loop, twisting is not easier than hard-coding each individual value?

Akina2021-10-13 11:44:44

If it is df pandas, then just do dictionary replacement.

strawdog2021-10-13 11:46:22